Created
June 4, 2016 18:49
-
-
Save TarasOsiris/90a3545abf7033ad1bf1a7f1728a11c9 to your computer and use it in GitHub Desktop.
Understanding Steering Behaviors: Seek
This file contains 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
the script is misnamed or you have a type-o in the class name.
SteeringSeek.cs should have the class named "SteeringSeek" not "Seek"