1
0
Fork 0

Scorpion movement

This commit is contained in:
Saibotk 2018-04-23 00:35:32 +02:00
parent dbd6700498
commit d741fddf3d
2 changed files with 9 additions and 9 deletions

View file

@ -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}

View file

@ -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) {