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 / Help with some maths?

Author
Message
Fluorescent
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 11th Dec 2014 09:22
Maths have never been anything I'm very good at so I thought I should ask for some help.

I'm trying to apply a physics force/impulse to my sprite. Sort of like a rocket engine. And I need to find the direction that the engine should be pointing. I know the velocity x and y I know the angle of the sprite so should I be able to use Sin and Cos to get the values for SetSpritePhysicsForce?

When I do, the sprite goes flying down the right side of the game world. Or it goes completely nuts and starts bounding around the world.

So clearly I am missing something, and this seems like a pretty standard run of the mill formula. So perhaps someone can point me in the right direction?
easter bunny
12
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 11th Dec 2014 22:51 Edited at: 11th Dec 2014 22:53
First: SetSpritePhysicsForce is in world coordinates, you might not be doing this correctly.
Quote: "I know the velocity x and y I know the angle of the sprite"

Not sure exactly what you mean...
If you already have the X/Y components of the velocity:


If you only have the angle:



Pretty sure that's how you do it. This code is untested


Audacia Games - Latest WIP - AUTOMAYTE 2.1, AppGameKit one click deploy to Android
"When you've finished 90% of your game, you only have 90% left"
Fluorescent
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 12th Dec 2014 10:24
Thank you! That really put me back on the right track.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 12th Dec 2014 12:05 Edited at: 12th Dec 2014 13:51
You may think this is being pedantic but in order to answer your question properly, it is important that we are all using the correct terminology.

Velocity is a vector.
Speed is a scaler.

They are very different things! Velocity has both speed and direction. Velocity is very different to speed although in many cases people seem to use the terms interchangeably - They are wrong!

When you say you have the velocity x and Y components do you realy mean you have the position that it is to be applied? Because if you actually have the velocity as a vector then you don\'t need any maths at all.

However, either way, here are some functions that should help:






@easter bunny Your code calculates a directional vector and multiplies it by speed twice(!)

[EDIT]
This function: getVelocityFromUnitVector() Assumes you have your directional vector as a unit vector - if not then you will need this as well:


and this:



easter bunny
12
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 14th Dec 2014 22:59 Edited at: 14th Dec 2014 23:03
Quote: "When you say you have the velocity x and Y components "

Oops, I meant X/Y components of the angle.


Audacia Games - Latest WIP - AUTOMAYTE 2.1, AppGameKit one click deploy to Android
"When you've finished 90% of your game, you only have 90% left"

Login to post a reply

Server time is: 2024-11-25 13:40:56
Your offset time is: 2024-11-25 13:40:56