Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / [DBP] Need some help with movement and rotation of sprites please.

Author
Message
DLS
19
Years of Service
User Offline
Joined: 6th Jul 2004
Location: Wet And Windy Britain
Posted: 20th Jun 2008 20:06
I'm trying to make my sprite rotate to point at where I clicked with the mouse and then have it move towards it.

I don't know how to get the angle from the sprite to the mouse co-ords.

I'm guessing its to do with trig but I can't for the life in me rember what to do with the cos and sin, other that divide sin and cos to get the tan.

Do I find the cos by taking the sprite x co-ord away from the desination x or am I completly wrong?

Bare in mind that I haven't activley done trig for over 10 years.

Any help would be of use. Either code/psudo code, or a forum link.

oh and one other thing I have done some searching on this matter and nothing seems to be coming up.

Thanks for any help you can give.

PC spec: AMD64 X2 @ 2Ghz, 1Gb DDR 400Ram, 1x 160Gb and 1x 300 gb HDD, 2x GForce FX7600GS 256Mb PCx in Sli mode, XP Home SP2
DLS
19
Years of Service
User Offline
Joined: 6th Jul 2004
Location: Wet And Windy Britain
Posted: 20th Jun 2008 21:45
I've Mangaged to the get Angle and Distance I need to where the mouse has been clicked. But now I've ran into a little problem.

I can't get the sprite to rotate properly. Can someone look at this code and tell me where I'm going wrong please.



If the angle is between 0 and 180 it flips 90 deg and then locks up. If its between 180 and 359 it does nothing.

PC spec: AMD64 X2 @ 2Ghz, 1Gb DDR 400Ram, 1x 160Gb and 1x 300 gb HDD, 2x GForce FX7600GS 256Mb PCx in Sli mode, XP Home SP2
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 20th Jun 2008 22:12
I thin you're trying to do too much, just straight out using ATANFULL should get you the angle.


Angle#=ATANFULL(DX#,DY#)
Rotate sprite 1,Angle#

Los Mineros are back in progress!
DLS
19
Years of Service
User Offline
Joined: 6th Jul 2004
Location: Wet And Windy Britain
Posted: 21st Jun 2008 15:46
I know that atanfull(x,y) gets the angle.

What I want to do is have the sprite gradually rotate to face that direction.

One thing I am finding quite strange is that the sprite keeps pointing the opposite on the North/South angles. Eg: If I click north of my sprite it turns the degrees south and visa versa.

Can anybody shed some light on this. Heres the code I got so far.



The sprite moves no problem just need to sort out the angle thing now.

PC spec: AMD64 X2 @ 2Ghz, 1Gb DDR 400Ram, 1x 160Gb and 1x 300 gb HDD, 2x GForce FX7600GS 256Mb PCx in Sli mode, XP Home SP2
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 21st Jun 2008 18:02
Oh, I see. I always hated trying to work with angles

I think you should post this in the DarkBASIC Pro board, there should be a lot more people there who can help with this.

Los Mineros are back in progress!
Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 21st Jun 2008 20:06
Change the following line



to



Reason is because the angle your getting is based on having Y start from the bottom of the screen to the top, being the top a positive value. Thats how we are taught. But on the coding side, the screen's Y value start at the top of the screen and continuos to the bottom as a positive value, thus we must invert the way the function works.

Further on my stuff at...
TurboSquid.com
The3dStudio.com
DLS
19
Years of Service
User Offline
Joined: 6th Jul 2004
Location: Wet And Windy Britain
Posted: 22nd Jun 2008 09:18
Thanks for solving that problem now I got a different issue that I overlooked.

I'm going to move the thread to the DBP board and see what happens there.

thanks again

PC spec: AMD64 X2 @ 2Ghz, 1Gb DDR 400Ram, 1x 160Gb and 1x 300 gb HDD, 2x GForce FX7600GS 256Mb PCx in Sli mode, XP Home SP2

Login to post a reply

Server time is: 2024-05-04 14:12:01
Your offset time is: 2024-05-04 14:12:01