• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GM Physics problem

Vallo92

Member
I am trying for the first time to use GM's integrated physics (I use version 2.3).
I wanted to create a simple pogo stick.
I created 2 objects:
- One representing the stick, to which I assigned a "Restituition" = 0. This way I set the stick not to bounce if it collides with the terrain.
- A spring object, which must be applied to the base of the stick object. The spring object must be glued to the base of the stick object (so it must follow all its movements). When it collides with the ground, it must transfer the impulse to the stick so that it can jump into the air.

Is the first approach right?
I read the manual and saw that the variables dedicated to GM's integrated physics are different from the "standard" motion variables, and above all they work differently.
Now here are my questions (if my previous reasoning is right):
- To "glue" the spring to the stick I wrote this code (inserted inside the stick object):
GML:
with (obj_spring) {
    phy_position_x = other.phy_position_x;
    phy_position_y = other.phy_position_y + (other.sprite_height/2); // stick sprite origin is in the middle center
}
But I read in the manual that it is not correct to directly modify the x and y values, since they overwrite the simulation values. Did I understand correctly? If yes, how can I solve this problem?
I also tried to create a joint between the two objects (physics_joint_distance_create), but then I can't move them properly anymore, since it seems that both objects affect the other physical characteristics.


- I can't understand how to transfer all the forces that are activated on the spring that collides with the ground, to the stick, so that the stick (and consequently the spring that is glued to it) moves. Can anyone give me some suggestions about this?
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
Use a weld joint to make the spring fixture attach to the stick fixture. :)


Once they are welded together, forces and impulses should act on them both as if they were one thing.
 

Vallo92

Member
@Nocturne Thanks for your answer!
I tried to create with joint between the stick and the spring with "physics_joint_weld_create" by inserting the same points in both the coordinates of the anchor points.
GML:
var _springA = instance_create_layer(x, y + (sprite_height / 2), layer, obj_Spring);
physics_joint_weld_create(self, _springA, x, y + (sprite_height / 2), 0, 0, 0, false);
The two instances are now connected without any problem, but I have some questions about that:

- If I set the Density of either object to 0, the pogo stick is no longer affected by gravity. Since I connect two instances with a joint, am I forced to set the same Density values? If I set different Density values, what becomes the "dominant" value between the two?
Same thing happens for the Restitution value. If, for example, I want to set the Restitution value to 1 for the spring (so that it bounces a lot), and the Stick Restitution value to 0.1 (so that it bounces a little, for example in case it falls sideways), when I do the test, and the spring collides, it falls down immediately, as if it inherits the Restitution value of the

- If I want to increase the force with which the pogo stick bounces, for example every touch on the ground of the spring the force increases by 0.1, how can I do it? From the object editor I can only enter a value for the Restitution. Can I increase this value via GML, or should I apply an impulse to each bounce?

Edit: I find a solution for my last question:
GML:
var rest = physics_get_restitution(fix_id);
physics_set_restitution(fix_id, rest + 0.1);
I think I have to put it in the spring instance, but the problem remains that it seems to have an influence on its Restitution value.
 
Last edited:
Top