Scorpion movement
This commit is contained in:
parent
dbd6700498
commit
d741fddf3d
2 changed files with 9 additions and 9 deletions
|
@ -84,7 +84,7 @@ Rigidbody2D:
|
||||||
m_UseFullKinematicContacts: 0
|
m_UseFullKinematicContacts: 0
|
||||||
m_UseAutoMass: 0
|
m_UseAutoMass: 0
|
||||||
m_Mass: 1
|
m_Mass: 1
|
||||||
m_LinearDrag: 0
|
m_LinearDrag: 0.1
|
||||||
m_AngularDrag: 0.05
|
m_AngularDrag: 0.05
|
||||||
m_GravityScale: 0
|
m_GravityScale: 0
|
||||||
m_Material: {fileID: 0}
|
m_Material: {fileID: 0}
|
||||||
|
|
|
@ -34,18 +34,18 @@ namespace Assets.Scripts.Entities {
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 distanceToEnemy = victim.transform.position - gameObject.transform.position;
|
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
|
//rotation
|
||||||
Vector3 localRotation = gameObject.transform.localRotation * Vector3.up;
|
Vector3 localRotation = gameObject.transform.localRotation * Vector3.up;
|
||||||
float angleToRotate = Mathf.Round(Vector3.SignedAngle(localRotation, distanceToEnemy.normalized, Vector3.forward));
|
float angleToRotate = Mathf.Round(Vector3.SignedAngle(localRotation, distanceToEnemy.normalized, Vector3.forward));
|
||||||
gameObject.transform.Rotate(0, 0, angleToRotate * rotationSpeed);
|
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) {
|
public void SetVictim(GameObject g) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue