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 / Trouble with SetSpritePhysicsVelocity

Author
Message
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 23rd Jul 2020 12:41

So I have this nice bit of code:

SetSpritePhysicsVelocity(Bullets[Bullets.length].SID, cos(0.0)*50.0, sin(0.0)*50.0)

According to my understanding, 0.0 should make it move at 0 degrees, that is, straight up. But it moves to the right. What am I missing?

Maybe 0 degrees means three o'clock instead?
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 23rd Jul 2020 12:58 Edited at: 23rd Jul 2020 12:59
Trigonometry...

Cos(0.0) = 1
Sin(0.0) = 0

So your code is setting the sprite speed to be x=50, y=0 which is "3oclock"


If you want 0 degrees to upwards (and any angle used to be clockwise) then use

SetSpritePhysicsVelocity(Bullets[Bullets.length].SID, sin(Angle#)*50.0, -cos(Angle#)*50.0 )


If your angle is always going to be 0 then:

SetSpritePhysicsVelocity(Bullets[Bullets.length].SID, 0, -50.0 )
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 23rd Jul 2020 13:46
Thanks, it works! cos/sin is one of those things I never really figured out. However, I don't want to make up new standards just because. It was only that I guessed that 0 degree was up because that felt most natural. But in page 598 of the guide, it is suggested that 3 o'clock is the default angle, going clockwise from there. So I just reworked my code from that, and it run fine now. (despite my broken physics, but whatevs)
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 23rd Jul 2020 16:02
@basicFanatic

Quote: "cos/sin is one of those things I never really figured out"

I strongly recommend to read up on how cos and sin work and what they really are.

There are a lot of good tutorials/videos about these, and it's pretty easy stuff ( it really is ).

You can thank me later


PSY LABS Games
Coders don't die, they just gosub without return

Login to post a reply

Server time is: 2024-04-18 13:24:13
Your offset time is: 2024-04-18 13:24:13