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

Message
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!

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
Posted: 2nd Jan 2018 23:01 Edited at: 2nd Jan 2018 23:05
i used

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)
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
Posted: 2nd Jan 2018 23:08 Edited at: 2nd Jan 2018 23:09

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)
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
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
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)
Posted: 3rd Jan 2018 00:37
Thanks guys, making all the appropriate variables into floats did the trick!
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)
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 !!!
Posted: 5th Jan 2018 19:41
That's very nice Captain, thanks!