Commit 5f119b2e by Tim Reiter

added Rocket "target lag" so the target can avoid the rocket.

parent f6b10275
......@@ -6,8 +6,9 @@ public class Rocket : MonoBehaviour
#region members
public int damagePoints = 15;
public float speed = 1;
public float pushForce = 20; //wie stark das target weggeschubst wird beim aufprall.
public float flyToTargetSpeed = 10f;
public float speed = 1f;
public float pushForce = 20f; //wie stark das target weggeschubst wird beim aufprall.
private Rigidbody2D body;
public Transform target;
......@@ -25,8 +26,9 @@ public class Rocket : MonoBehaviour
//update direction:
Vector3 direction = target.position - transform.position;
body.velocity = (float)speed * direction.normalized;
transform.rotation = Quaternion.Euler(0, 0, -Mathf.Rad2Deg * Mathf.Atan2(direction.x, direction.y));
body.velocity = Vector2.Lerp(body.velocity, (float)speed * direction.normalized, Time.deltaTime * flyToTargetSpeed);
Quaternion newRotation = Quaternion.Euler(0, 0, -Mathf.Rad2Deg * Mathf.Atan2(direction.x, direction.y));
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * flyToTargetSpeed);
}
void OnTriggerEnter2D(Collider2D other)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment