• 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!

GML trying to make a (physics)-object stick to a rotating (physics)-object

Yavga

Member
I can't seem wrap my head around it, just pointers would be a big help: here's the issue:

[picture removed]

-The game takes place in a physics world-

The skeleton hand are able to grapple to the giant (spinning) sun wheel. (and all blue surfaces)

The sun wheel is rotating and while I am able to latch the hands on any grabable surface I am doing so by creating an object that "floats" stationary which is being created at the press of a button when the hands meet collision.

Here's a simple ilustration of the idea how the current "latch" works:
Code:
// Create PADDLE for "grabbing" on right shoulder trigger if collision event is being met
if gamepad_button_check_pressed (0, gp_shoulderrb)
and grabbingallowed = true
    {
    image_index = 1
        if(place_meeting(x,y+2,obj_grabbercollision))
        or(place_meeting(x,y-2,obj_grabbercollision))
        or(place_meeting(x+2,y,obj_grabbercollision))
        or(place_meeting(x-2,y,obj_grabbercollision))
            {
            instance_create_layer(self.x,self.y,"alayer",obj_fronthand_grabforce)
            instance_create_layer(self.x,self.y,"alayer",obj_fronthand_grab)
            }
    }
This means that the "grab" remains in place and will not rotate along with the wheel.


What roads could I take in order to write a code that makes the hands latch on to any surface in such a way that they do not ignore any physics currently active on the "other" object? (moving platform, rotating platform etc.)

I was brainstorming about making the moving collision-object create an (invisible) fixture around the hand(s) at the point of contact but I couldn't figure out how to get the exact x- and y- location of the point the collision happens at to use for fixture creation, besides that this sounds like a very resource heavy workaround anyway which probably can be achieved way more easily.

any pointers would be greatly appreciated! I managed to do everything without help so far and it has been a great challenge so far but I'm getting frustrated by this problem I can't find the solution for right now.
 
Last edited:
S

SuG4Ru

Guest
This maybe help

Code:
// Variables

image_angle           = obj_player_player1.image_angle  ;  // Copying image_angle of another object in this case image angle of object1 is apply to image_angle object2
object_to_stick       = obj_player_player1              ;  // Here add object you want to stick object1 stick to object2 [object 2 is where this code add]
angle_of_object_use   = obj_player_player1              ;  // If you want copy direction of some object and apply to this object
direction_of_object   = 315                             ;  // degreases in which way from object 1 want to show
distance_of_object_x  = 100                             ;  // distance from object
distance_of_object_y  = 100                             ;  // distance from object
angle_object          = 0                               ;  // If you want rotate object2
initial_angle         = -80                                ;  // I think its same like angle_object

// Piece of the code

x = object_to_stick.x + lengthdir_x(distance_of_object_x, direction_of_object + object_to_stick.image_angle);
y = object_to_stick.y + lengthdir_y(distance_of_object_y, direction_of_object + object_to_stick.image_angle);
image_angle = angle_object + angle_of_object_use.image_angle + initial_angle;


//For write possition
//
//        D        B
//        |       /
//        |      /
//        |     /
//        |    /
//        |   /
//        |  /
//        | /
//        |/_______C
//      A
//
//   A = object_to_stick       // From Variables
//   B = direction_of_object   //
//   C = distance_of_object_x  //
//   D = distance_of_object_y  //

This degreasses doesnt need this only for if you want to make two object like one
 

Yavga

Member
This maybe help

Code:
// Variables

image_angle           = obj_player_player1.image_angle  ;  // Copying image_angle of another object in this case image angle of object1 is apply to image_angle object2
object_to_stick       = obj_player_player1              ;  // Here add object you want to stick object1 stick to object2 [object 2 is where this code add]
angle_of_object_use   = obj_player_player1              ;  // If you want copy direction of some object and apply to this object
direction_of_object   = 315                             ;  // degreases in which way from object 1 want to show
distance_of_object_x  = 100                             ;  // distance from object
distance_of_object_y  = 100                             ;  // distance from object
angle_object          = 0                               ;  // If you want rotate object2
initial_angle         = -80                                ;  // I think its same like angle_object

// Piece of the code

x = object_to_stick.x + lengthdir_x(distance_of_object_x, direction_of_object + object_to_stick.image_angle);
y = object_to_stick.y + lengthdir_y(distance_of_object_y, direction_of_object + object_to_stick.image_angle);
image_angle = angle_object + angle_of_object_use.image_angle + initial_angle;


//For write possition
//
//        D        B
//        |       /
//        |      /
//        |     /
//        |    /
//        |   /
//        |  /
//        | /
//        |/_______C
//      A
//
//   A = object_to_stick       // From Variablec
//   B = direction_of_object   //
//   C = distance_of_object_x  //
//   D = distance_of_object_y  //
Ha! Actually I stumbled upon this earlier while looking for a solution with the search bar, but I didn't understand it properly at the time. I'll cool down for a bit and try to read it again. Thanks!
 

Jezla

Member
When using the physics system, the way to do this is to use joints. In your case, I'd suggest either a prismatic or revolute joint. There's no need to create additional objects.

Also, there's no need to use the 'self' keyword when referring to an instances own properties (such as x and y position).
 

Yavga

Member
When using the physics system, the way to do this is to use joints. In your case, I'd suggest either a prismatic or revolute joint. There's no need to create additional objects.

Also, there's no need to use the 'self' keyword when referring to an instances own properties (such as x and y position).
Thanks, I'll remember.

In fact I used a lot of joints already to connect the limbs of my skeleton, initially I had a lot of problems with them because the chain of limbs would break under pressure so I've learned that by creating a rope joint between the first and last limb as well it got a lot stabler, with that and the wisdom that the total mass of all objects should never be a working force any bigger than 1:10, together with that and running the physics at 4* the room speed and setting the iterations at 20 everything works!

But how am I able to create a joint between a collision-object and another at the right offset? (as in, how can I get the collision offset at the point of impact?)
 
Top