Skip to content

Instantly share code, notes, and snippets.

@TarasOsiris
Created June 4, 2016 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TarasOsiris/90a3545abf7033ad1bf1a7f1728a11c9 to your computer and use it in GitHub Desktop.
Save TarasOsiris/90a3545abf7033ad1bf1a7f1728a11c9 to your computer and use it in GitHub Desktop.
Understanding Steering Behaviors: Seek
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 );
}
}
Copy link

ghost commented Feb 23, 2020

the script is misnamed or you have a type-o in the class name.
SteeringSeek.cs should have the class named "SteeringSeek" not "Seek"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment