Legacy GM how does motion_add work?

S

Shadowblitz16

Guest
so I was googling since this question was answered on the old forums but it looks like it got deleted

anyways I was just wondering how motion_add worked in gms?

if you have a speed variable and a directional variable how do you add motion in the desired direction?
I thought it had something to do with sin and cos
 
S

Shadowblitz16

Guest
@FrostyCat
this doesn't explain the math behind it
I wanted to know the actual way it works
not how to use it
 

FrostyCat

Redemption Seeker
This is what it does:
Code:
//Equivalent to motion_add(dir, spd)
hspeed += spd*cos(pi/180*dir);
vspeed -= spd*sin(pi/180*dir);
 
P

Pixelnaut

Guest
hey everyone. so I read the entry for this function in the manual, and I read this thread, however I am pretty new still to programming and GML and I don't quite understand WHY you'd want to use this function? can anyone help me out? thanks!
 

TheouAegis

Member
hey everyone. so I read the entry for this function in the manual, and I read this thread, however I am pretty new still to programming and GML and I don't quite understand WHY you'd want to use this function? can anyone help me out? thanks!
Have you studied vector physics in school? Have you studied how a forward propellant combined with a downward gravitational acceleration affects the movement of an object? Have you studied how the collision between two objects affects the motion of each of the objects in the Collision?
 
P

Pixelnaut

Guest
Have you studied vector physics in school? Have you studied how a forward propellant combined with a downward gravitational acceleration affects the movement of an object? Have you studied how the collision between two objects affects the motion of each of the objects in the Collision?
OOPS. Got me bud! Thanks so much for the amazing, thoughtful, helpful answer.
 

GMWolf

aka fel666
OOPS. Got me bud! Thanks so much for the amazing, thoughtful, helpful answer.
I 93% believe this was a question to better understand where you are at in order to better explain the concept.
Though, could be perceived as condensing...

But simply put:
Think of a space ship in space.
If you thrust in a direction, you will accelerate in that direction, rather than instantly move In that direction.

If you thrust north for 1s, then East for 1s, then you will be moving North-East.

That is what this function is for. It is to accelerate (thrust) in a given direction.
(Naturally this applies to a lot more than just spaceships. In the real life, all objects work that way)
 
Last edited:
Top