How to attach and object to another object?

H

heanfry

Guest
So an object is moving from for example 1920 to 0, and an another object stay's in collision.

I want the other object always being attached to the first object, how can i do it?

Thank you guys!
 

jujubs

Member
First you check if the second objects is colliding with the first.
If it is (which it should be once they collide), make it's XY equals to the first object.
I'd try something like

Code:
if(collision == true)
{
    x = firstobject.x;
    y = firstobject.y;
}
Note that there are probably better ways to do this, but for testing purposes, this should be fine.
 
A

Andrea N

Guest
First you check if the second objects is colliding with the first.
If it is (which it should be once they collide), make it's XY equals to the first object.
I'd try something like

Code:
if(collision == true)
{
    x = firstobject.x;
    y = firstobject.y;
}
Note that there are probably better ways to do this, but for testing purposes, this should be fine.
But if you use:
x = firstobject.x;
y = firstobject.y;
i think you are going to overlap the two objects, i think you can try to use, when the two objects collide, "mp_potential_step_object ( firstobject.x, firstobject.y, speed, obect_to_follow);
Or "move_towards_point (....)"
 

CloseRange

Member
using mp_potential is way more work than is needed.
But just setting one's x to another does overlap the 2 objects.

I'd suggest saving the collision of the inital offset of the 2 objects first:

Code:
/// create event
hit = false;
x_off = 0;
y_off = 0
Code:
/// step event
if(collision) {
    if(!hit) {
       hit = true;
       x_off= x -firstobject.x;
       y_off= y -firstobject.y;
    }
    x = firstobject.x + x_off;
    y = firstobject.y + y_off;
}
 
O

orSQUADstra

Guest
I think something like this would be a bit simpler:
Code:
if (collision)
{
    x += firstobject.x-firstobject.xprevious;
    y += firstobject.y-firstobject.yprevious;
}
as you wouldn't have to have additional variables. Not saying it makes a big difference, but I find it to be better not to use variables where you don't need to
 
Top