GML How to set Physics SPEED ?

Director_X

Member
HI.

Running into a bit of a problem. I need my physics object to move towards the mouse, and set its speed when I right-click.

Code:
// Currently this whooshes towards the mouse pointer quite fast.
physics_apply_impulse(x, y, -(x-mouse_x), -(y-mouse_y));

//I need to set it's speed.
phy_speed_x = ??;
phy_speed_y = ??;
Problem with the physics in GM is that the speed is set on the Axis, and not an actual speed setting.

So if for example, I set the following:
phy_speed_x = 10;
phy_speed_y = 10;
It will change BOTH the speed, and the ANGLE (or is it x,y coordinates?) of X and Y by 10 degrees!!

So how do I change just the speed, without changing ANY angles???!

Please help.
Thanks.
 
Last edited:

kburkhart84

Firehammer Games
I don't ever mess with the physics engine, but it seems that a little trigonometry would solve this. A little Vector math would have the same result. I would start with that. If you have the speed of 10, then at exactly a 45 degree angle you would end up with something just above 7 for the x and y values.
 
To be entirely honestly you'd likely be better off looking at some tutorials and coding your own physics engine.

To paraphrase another dev that discussed it "GMSs built in systems for complex things like physics are a black box you can't really see inside or fully control". So it's often better to code it yourself so you have full and direct control over how your mechanics for various things work. That or use a physics engine someone has made and given people permission to use in their projects so it's completely laid open and you can see how everything works.
 
Last edited:
while I agree the GMS physics is mehh, in physics world, speed is a product of acceleration (force) over time. You don't set the speed per se, you apply forces, which in turn give a speed to your instance as times goes.
 

Director_X

Member
Thanks for the replies folks. I've decided not to bother with physics anymore.

It's overly complicated (for a novice coder like me) as if objects are physics enabled - they don't interact with code like normal objects. And some functions are READ ONLY, for example phy_speed, so we can CHECK phy_speed == 5 but we CANNOT assign it phy_speed = 5; (How was it 5 to begin with? Why cannot we SET it as well?!).

Plus some physics commands don't even show up in the manual (not meta-linked?) and we have to discover them through some round-about way. Too much hassle.

Thanks again.
 
Top