How do I move an object (particle-emitter) towards the player who are most certainly moving around? I have no idea on how I should do this, and I could not find an answer to this in the answered questions.
My game is made in c#, and Iām pretty new to programming so be nice
You must repeat the same sequence at each Update: get the target position, then move the object in the target direction a small distance proportional to the desired speed and to the time elapsed since the last frame (Time.deltaTime). The easiest way to do that is with Vector3.MoveTowards (badly explained in the docs):
Transform target; // drag the player here
float speed = 5.0f; // move speed
void Update(){
transform.position = Vector3.MoveTowards(transform.position, target.position, speed*Time.deltaTime);
}
Vector3.MoveTowards(from, to, distance) returns a point in the line from-to distant distance units from the the from point. The distance parameter is internally clamped to never return a point ahead the to point.
NOTE: This script must be attached to the particle object.
#pragma strict
// drag the player here
var speed:float = 5.0f; // move speed
function Start () {
}
function Update () {
transform.position = Vector3.MoveTowards(transform.position, Vector3(32,15,-92), speed*Time.deltaTime);
}