I know that I not the first that ask that question but I can’t find a good answer for my problem.
When my character getting hit, there is a “force shield” that sapwns and defend me from hits for 5 seconds. When it spawns, it should move with me, but it not, it just spawns and stay in the same plase all the time. I tried to get help from this answer but now the shield move always on the Z axis and not after me (it spawns and move on the Z axis even when I don’t move). How I can make the shield go with me and always be excatly on the player position?
This is what I did:
var target : Transform;
var damping = 6.0;
var speed = 20.0;
function Awake()
{
target = GameObject.FindWithTag("Player").transform;
}
function Update ()
{
var rotation = Quaternion.LookRotation(target.position, transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
(I can’t set the “target” var in the inpector).
Sorry for poor english.