slowly rotate an object towards another object
Posted
by numerical25
on Stack Overflow
See other posts from Stack Overflow
or by numerical25
Published on 2010-01-27T20:48:15Z
Indexed on
2010/06/07
2:42 UTC
Read the original article
Hit count: 289
I have an object that points in the direction of another object (i.e. it rotates to the direction that the second objects x and y coordinates are at) below is the code I use.
var distx = target.x - x;
var disty = target.y - y;
var angle:Number = Math.atan2(disty, distx);
var vx:Number = Math.cos(angle) * cspeed;
var vy:Number = Math.sin(angle) * cspeed;
rotation = angle * 180/Math.PI;
x += vx;
y += vy;
as you can see. Not only does it rotate towards the target object, but it also moves towards it too. When I play the movie, the object instantly points to the targeted object and moves towards it.
I would like for it to slowly turn towards the object instead of instantly turning towards it. anyone know how to do this.
© Stack Overflow or respective owner