Skip to content

Instantly share code, notes, and snippets.

@kiranmaya
Forked from TarasOsiris/SteeringSeek.cs
Created August 16, 2016 14:20
Show Gist options
  • Save kiranmaya/deb9466b4d9d4fe95d70e3234a270eaf to your computer and use it in GitHub Desktop.
Save kiranmaya/deb9466b4d9d4fe95d70e3234a270eaf 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 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment