Page 1 of 1

help

PostPosted: Sun Aug 01, 2010 11:44 am
by savvy
how do i get an actor to follow the mouse in rotation, as in a turret following the mouse to aim? cos im stumped

Re: help

PostPosted: Sun Aug 01, 2010 12:37 pm
by jimmynewguy
if you mean rotating to face the mouse then use
Code: Select all
angle=direction(x,y,xmouse,ymouse)/nframes;

But for some reason xmouse and ymouse always tend to be off so your better off making an actor called mouse and on create actor setting it to follow mouse then change the turrent code to
Code: Select all
angle=direction(x,y,mouse.x,mouse.y)/nframes;


EDIT: Put this in draw actor

Re: help

PostPosted: Sun Aug 01, 2010 2:53 pm
by savvy
ok, thanks

Re: help

PostPosted: Sun Aug 01, 2010 2:56 pm
by savvy
it still doesnt work

Re: help

PostPosted: Mon Aug 02, 2010 2:14 am
by DilloDude
jimmynewguy wrote:if you mean rotating to face the mouse then use
Code: Select all
angle=direction(x,y,xmouse,ymouse)/nframes;

But for some reason xmouse and ymouse always tend to be off ...

xmouse and ymouse are screen coordinates. So to use them, use
Code: Select all
direction(xscreen, yscreen, xmouse, ymouse);


In you're example, you're adjusting angle. angle is for movement, and requires directional_velocity.
If you want to adjust the animation use
Code: Select all
double dir = direction(xscreen, yscreen, xmouse, ymouse);
animpos = (int)((dir + 5) * .1) % 36;

This is for a 36 frame rotation animation (for other values you'll need to adjust the numbers.

Re: help

PostPosted: Mon Aug 02, 2010 3:22 am
by jimmynewguy
DilloDude wrote:In you're example, you're adjusting angle. angle is for movement, and requires directional_velocity.

:shock: when i type fast i do weird things, i meant angle to be animpos...but your code is better :D

Re: help

PostPosted: Mon Aug 02, 2010 11:05 am
by savvy
ok, its still not working. heres the actual thing

Re: help

PostPosted: Mon Aug 02, 2010 3:16 pm
by jimmynewguy
the animtion of your turrent rotating should start at zero degrees (facing right) and rotate counterclockwise in order for the code to work :)

Re: help

PostPosted: Mon Aug 02, 2010 3:57 pm
by savvy
o, ok

Re: help

PostPosted: Mon Aug 02, 2010 4:13 pm
by savvy
ok, now with that done i need to know how to make a bullet travel in the direction of the mouse.
(ive never done rotation code Bfore)

TOPIC CLOSED

PostPosted: Wed Aug 04, 2010 8:22 pm
by savvy
dont worry, i have it done. -CLOSED TOPIC-