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.

AppGameKit Classic Chat / How do i get a sprite to move in relation to its angle?

Author
Message
THE_NOTORIOUS_PIGGY
7
Years of Service
User Offline
Joined: 17th Jun 2016
Location:
Posted: 25th Jul 2016 10:58
Hello. I am trying to make a simple car game, but I cant seem to fix this problem.

At the start, the sprite moves fine. When I turn it, it goes in the correct direction, and then completely breaks lol.
Basically I have 2 buttons. The first one changes direction, and the second one also changes direction but in the other way. How can I make it so that the two buttons change the direction and the car goes in the direction that it is facing? I tried my best in the above code but everything I ever make always breaks haha

Thanks guys for any help you can offer
Markus
Valued Member
19
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 25th Jul 2016 19:26
in float,from the sprite angle you get a direction in x and y, this * distance is your step to next position

dx= Cos(angle)*distance
dy=-Sin(angle)*distance

Positionx = Positionx + dx
Positiony = Positiony + dy
AGK (Steam) V2.0.20 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 25th Jul 2016 20:12 Edited at: 25th Jul 2016 20:14
Hey Mr. N! There's a few things you're getting a bit confused about, so I'll attempt to edit your code so it works:



If I understood your original code correctly, than I'm pretty sure this will work. :p Good luck! Hope this helps make some sense.

Edit: Oops, sorry Markus, I didn't see your post until after I posted, guess it didn't updated.
Markus
Valued Member
19
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 25th Jul 2016 20:57
@JLMoondog Don't worry.
AGK (Steam) V2.0.20 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
THE_NOTORIOUS_PIGGY
7
Years of Service
User Offline
Joined: 17th Jun 2016
Location:
Posted: 25th Jul 2016 21:40
Thank you very much my friend!

Login to post a reply

Server time is: 2024-03-29 06:13:01
Your offset time is: 2024-03-29 06:13:01