From d741fddf3d2445ab7db1134c58681d83b166e481 Mon Sep 17 00:00:00 2001 From: Saibotk Date: Mon, 23 Apr 2018 00:35:32 +0200 Subject: [PATCH] Scorpion movement --- Assets/Prefabs/Scorpion.prefab | 2 +- Assets/Scripts/Entities/Enemy.cs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Assets/Prefabs/Scorpion.prefab b/Assets/Prefabs/Scorpion.prefab index b926bfe..1a31e25 100644 --- a/Assets/Prefabs/Scorpion.prefab +++ b/Assets/Prefabs/Scorpion.prefab @@ -84,7 +84,7 @@ Rigidbody2D: m_UseFullKinematicContacts: 0 m_UseAutoMass: 0 m_Mass: 1 - m_LinearDrag: 0 + m_LinearDrag: 0.1 m_AngularDrag: 0.05 m_GravityScale: 0 m_Material: {fileID: 0} diff --git a/Assets/Scripts/Entities/Enemy.cs b/Assets/Scripts/Entities/Enemy.cs index 6172e57..2bb5c3e 100644 --- a/Assets/Scripts/Entities/Enemy.cs +++ b/Assets/Scripts/Entities/Enemy.cs @@ -34,18 +34,18 @@ namespace Assets.Scripts.Entities { } Vector3 distanceToEnemy = victim.transform.position - gameObject.transform.position; - - if(distanceToEnemy.magnitude < attack.GetRange()) { - return; - } - - // movement - body.velocity = new Vector2(distanceToEnemy.normalized.x, distanceToEnemy.normalized.y) * speed; - //rotation Vector3 localRotation = gameObject.transform.localRotation * Vector3.up; float angleToRotate = Mathf.Round(Vector3.SignedAngle(localRotation, distanceToEnemy.normalized, Vector3.forward)); gameObject.transform.Rotate(0, 0, angleToRotate * rotationSpeed); + + if ( distanceToEnemy.magnitude < attack.GetRange() ) { + return; + } + // movement + body.velocity = new Vector2(distanceToEnemy.normalized.x, distanceToEnemy.normalized.y) * speed; + + } public void SetVictim(GameObject g) {