vector - moving my object with transform.Translate make it move in wrong way -
i'm having hard time unity trying translate simple object. object move in 3 dimension world on x , z axis. function i'm using translate function of transform of gameobject. x , z position i'm trying move object.
transform.translate (( new vector3(x - transform.position.x ,0,z - transform.position.z)).normalized * time.deltatime * speed,space.world);
so here's problem i'm dealing : if result of calcul following vector : (0,0,-1.0)
, object move in wrong direction.
example :
starting position (25.16, 1.0, 12.0)
final position after translate function : (25.6, 1.0, 12.1)
any appeciate me understand this.
i'm using script in 1 of projects move gameobject point, attach on game object , enter x , y in finpos.
using unityengine; public class movementanimation : monobehaviour { public vector3 finpos; public bool loop = true; public int speed = 1; private vector3 startpos; private float starttime; private float lenght; void start () { startpos = this.transform.position; starttime = time.time; lenght = vector3.distance(startpos, finpos); } void update () { if (this.transform.position == finpos) { if (loop) { this.transform.position = startpos; starttime = time.time; } } else { float distance = (time.time - starttime) * speed; this.transform.position = vector3.lerp(startpos, finpos, distance / lenght); } } }
Comments
Post a Comment