-
-
Save kiranmaya/deb9466b4d9d4fe95d70e3234a270eaf to your computer and use it in GitHub Desktop.
Understanding Steering Behaviors: Seek
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class Seek : MonoBehaviour | |
{ | |
private Transform pointer; | |
public float speed = 1.0f; | |
public float mass = 1.0f; | |
private Vector2 curVelocity; | |
private void Start() | |
{ | |
pointer = FindObjectOfType<Pointer>().transform; | |
curVelocity = Vector2.zero; | |
} | |
private void Update() | |
{ | |
Vector2 desiredVelocity = (pointer.position - transform.position).normalized * speed; | |
Vector2 steering = desiredVelocity - curVelocity; | |
steering = steering / mass; | |
curVelocity += steering; | |
transform.Translate(curVelocity * Time.deltaTime ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment