GML [SOLVED]Moving physics objects together/Joints

Carloskhard

Member
In other words, I have a code that moves a certain phy_object in circles (around a planet, so Angle and position are changing). The code works for attaching objects to planets and it is the following(Feel free to use it):
/// @description attach_to_planet(parent_attached,pos_ang,dist);
/// @param parent_attached
/// @param pos_ang
/// @param dist
//run inside the object wich is attached to the planet

var dist,attach,pos_ang;

attach = argument[0];
pos_ang = argument[1];
if (argument_count>2)dist = argument[2]
else dist = attach.radioDist;

if(attach.liquid_planet)dist +=50;


phy_position_x = attach.x + lengthdir_x(dist,pos_ang+attach.image_angle);
phy_position_y = attach.y + lengthdir_y(dist,pos_ang+attach.image_angle);
angle = point_direction (x,y,attach.x,attach.y);
phy_rotation = -angle -90;

The problem is that if I do that, when my ship lands on that phy_object;which is a platform to land; it doesn´t generate friction and it slips like ice-skating, because the platform is not technically moving, but teleporting.

So, I was wondering if I could somehow make the platform move exactly the same but updating phy speeds so the ship gets pulled together with the platform because of friction.

The game I'm implementing this on is the one on my signature and you can see a gif of what I mean here:

As you can see, when landed on the planet the friction works perfectly since the planet is moving with phy_angular_velocity, but the platform don't.
Thanks for the help!
 

Carloskhard

Member
You could try attaching stuff to the planet either using joints or by adding additional fixtures to the planet instance.
Woah, those are complex but good ideas. Thanks for the inspiration! I'll try and tell you what I got.

EDIT:
I implemented the idea of @flyingsaucerinvasion like this:
Each time I create a new object attached to a planet(meaning its spinning with it) I run once this code on it which adds a fixture to the father planet where the object is.
I used the function polygon ficturtes cause it allow me to use offsets.
The code is the following:
/// @description Create fixture attached to planet
if(planeta_padre != noone){
var dist_center =point_distance(x,y,planeta_padre.phy_position_x,planeta_padre.phy_position_y);
var spr_hwidth = sprite_width/2;
var spr_hheight = sprite_height/2;

with(planeta_padre){
var fix2 = physics_fixture_create()

physics_fixture_set_polygon_shape(fix2);
physics_fixture_add_point(fix2,-spr_hwidth,-dist_center-spr_hheight)
physics_fixture_add_point(fix2,spr_hwidth,-dist_center-spr_hheight)
physics_fixture_add_point(fix2,spr_hwidth,-dist_center+spr_hheight)
physics_fixture_add_point(fix2,-spr_hwidth,-dist_center+spr_hheight)

physics_fixture_bind(fix2, id);
physics_fixture_delete(fix2);
}
}
Now the fixture is created and the platform moves so is always alligned with it,however..
My problem after all of this is that now I don't have collision event between the platform and the ship so I should create another fixture/collision box to check for that,which is much more expensive so I think its time to try the other method: joints.

EDIT 2:
So definetly the joint method was better! I've added a joint connection between the platform and the planet and now I have everything working fine! Collisions work in each object independently and the platform follows the planet by physically moving, so the friction with the ship is working :)

I'll post an update with more info about this and some gifs in the post of my game if anyone wants to see more.
Problem solved!
 
Last edited:
Top