Newgrounds.com — Everything, By Everyone.

Checking login status…

USERNAME:

PASSWORD:

Logging in…

Logged in as:
.
Logging out…
Inbox My Account Log Out


Forum Topic: Sidescroller aiming help!

(51 views • 2 replies)

This topic is 1 page long.

<< < > >>
None

helxliankid

Reply To Post Reply & Quote

Posted at: 5/17/08 02:21 PM

helxliankid LIGHT LEVEL 07

Sign-Up: 07/27/05

Posts: 34

I'm making a sidescroller, fantasy platformer. And I want the character to be able to cast spells and have his hand face out to where the mouse is. I have the registration point on his arm as his shoulder, but I don't know how to properly rotate his arm to the mouse point. Can anyone, please help me with this?


None

UnknownFury

Reply To Post Reply & Quote

Posted at: 5/17/08 02:30 PM

UnknownFury EVIL LEVEL 21

Sign-Up: 08/10/05

Posts: 5,041

Use trigonometry. Calculate the x distance from the mouse and the y distance. Then use the atan2 function to calculate the angle and rotate accordingly.

xd = _x - _root._xmouse;
yd = _y - _root._ymouse;
_rotation = Math.atan2(yd, xd);

Because your arm MC is inside another its going to be a bit more complicated I guess and you'll have to use localToGlobal.


None

helxliankid

Reply To Post Reply & Quote

Posted at: 5/17/08 02:48 PM

helxliankid LIGHT LEVEL 07

Sign-Up: 07/27/05

Posts: 34

I'm still a bit confused. Can you explain what the LocaltoGlobal function is?


All times are Eastern Daylight Time (GMT -4) | Current Time: 02:02 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!