|
I want to make a cube follow me around. I thought it would make a good script however I need to "link it" to my position so I made a public transform. However this isn't showing up when I apply the script for me to drag an object onto...Any help would be much appreciated. using UnityEngine; using System.Collections; public class Follow : MonoBehaviour {
void Start () { chaseVel = (3,0,3); }
}
(comments are locked)
|
|
To be completely correct here, instead of:
you should have something along the lines of:
However, multiplying two vectors together doesn't really make sense. To apply a non-uniform magnitude like that, you would need to multiply each component of the vector. Thus, instead of multiplying two vectors together like this:
you want to do this:
Also,
should probably be
Finally, the whole script probably won't work well as it is because you're updating the position by a constant value once per frame. The Update() function gets called once per frame, so at lower framerates your object will lag and at higher rates it will get to the player faster. So firstly, move this stuff from the Update() function to the LateUpdate() function -- this way, the player's position will be correct. And multiply your chaseDir by Time.deltaTime to ensure that the object always follows the player smoothly. Your final code might look like this:
(comments are locked)
|
|
Why is it that you have to parse each vector? I thought that was how vector multiplication was handled. Also, this.position and transform.position are not the same? Thank you very much your full answer it is very helpful and insightful. I did know about that fixed update though, thank you.
(comments are locked)
|
