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 to find new sprite position from angle and speed?

Author
Message
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 2nd Jan 2018 22:47
I'm maths challenged, and I need some kind soul to instruct me how to to have a sprite move across the screen according to its angle and speed. I know the sprite's current x, y, angle, and the distance I want it to travel.

Here's what I've tried...


But when I try to change the angle as it moves, it doesn't do what I expect.

Any help would be appreciated!

puzzler2018
User Banned
Posted: 2nd Jan 2018 22:54
That code works perfect for me

Setting line

15... SetSpriteAngle(spr, 0) // goes right
15... SetSpriteAngle(spr, 90) // goes down
15... SetSpriteAngle(spr, 180) // goes left
15... SetSpriteAngle(spr, 270) // goes up

Or am i misunderstanding you
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Jan 2018 23:01 Edited at: 2nd Jan 2018 23:05
i used


in your case


https://en.wikipedia.org/wiki/Acceleration
AGK (Steam) V2017.12.12 : Windows 10 Pro 64 Bit : AMD (17.12.1) Radeon R7 265 : Mac mini OS High Sierra (10.13)
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 2nd Jan 2018 23:02 Edited at: 2nd Jan 2018 23:06
Its because you are using integers and needed to use floats (add # to position and even angle variables). If you use integers then the movement gets truncated and so it doesnt move right (it moves in jerks).

Your maths is sound....just the variables needed to change type. And if you do change an angle then save it back to the sprite too.

This code goes in a nice circle
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Jan 2018 23:08 Edited at: 2nd Jan 2018 23:09
Quote: "add # "

you can also use local blah as float
so u not need to enter # always.

at main.agc top you should use
#option_explicit
AGK (Steam) V2017.12.12 : Windows 10 Pro 64 Bit : AMD (17.12.1) Radeon R7 265 : Mac mini OS High Sierra (10.13)
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 2nd Jan 2018 23:10
The point was he needs to use floats - doesnt really matter how he does that as long as he does Either way works
puzzler2018
User Banned
Posted: 2nd Jan 2018 23:14
Notice how the slightest thing can effect everything - like C++ missing that all important semi-colon, in this case the #, all good fun
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Jan 2018 23:16 Edited at: 2nd Jan 2018 23:19
Quote: "The point was he needs to use floats"

yes me thought he declared it elsewhere. and had a problem in sin/cos sign.

Quote: "Notice how the slightest thing can effect everything"

one char can break a app with thousands rows.
AGK (Steam) V2017.12.12 : Windows 10 Pro 64 Bit : AMD (17.12.1) Radeon R7 265 : Mac mini OS High Sierra (10.13)
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 3rd Jan 2018 00:37
Thanks guys, making all the appropriate variables into floats did the trick!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 3rd Jan 2018 00:51
use also the debugger and just copy this miraculous variables into for watching
AGK (Steam) V2017.12.12 : Windows 10 Pro 64 Bit : AMD (17.12.1) Radeon R7 265 : Mac mini OS High Sierra (10.13)
Captain Ouais
20
Years of Service
User Offline
Joined: 12th Dec 2003
Location: France
Posted: 3rd Jan 2018 21:04
Hello !
here's a function that moves a sprite forward by its angle, if that's what you need :

I do what i do !!!
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 5th Jan 2018 19:41
That's very nice Captain, thanks!

Login to post a reply

Server time is: 2024-11-24 04:02:22
Your offset time is: 2024-11-24 04:02:22