S
Simonbee10
Guest
I tried to create a way to make objects push eachother like this:
[O] = Object
-> = moving direction
Example:
[O] -> [O]
This will make them both go right, but a bit slower.
[O] -> <-[O]
This will make them stop, or the one with more speed and/or weight will overpower the other.
[O]->[O]->
This will make the right one go a little faster
[O]->[O]-> <-[O]
the two left one will probably win and push left at a certain speed.
I want to create this using weight and speed. If an object has more weight and speed it can push way more easily then an object that has less weight and/or speed. I'm also trying to create this without naming the objects so that I can create new object and give them the same parent/code and because of that they should behave the same.
This is my code so far (in step):
I managed to make the smaller object move me but I can't move the smaller object. I tried to move myself(a different object that doesn't move by itself) but it moves buggy.
I've also tested some things. I can't move the smaller object because of this code:
hsp = dir * -Espeed + fhsp
dir = direction
Espeed = extra speed
fhsp = friction speed
//shouln't matter though.
Before this code alot of different code is being run to see what dir, Espeed and fhsp is. After the code it just tests for walls and does:
x += hsp;
If I remove the whole hsp = di... then I'm able to move the smaller object although the smaller object doesn't work though.
I would really appriciate it if someone could help me with this.
Thank you in advance
I would also want to create a vertical version of this but that will come after I've completed this code.
[Note]: I,m still a beginner at game maker and english isn't my native language. Thanks for understanding
[O] = Object
-> = moving direction
Example:
[O] -> [O]
This will make them both go right, but a bit slower.
[O] -> <-[O]
This will make them stop, or the one with more speed and/or weight will overpower the other.
[O]->[O]->
This will make the right one go a little faster
[O]->[O]-> <-[O]
the two left one will probably win and push left at a certain speed.
I want to create this using weight and speed. If an object has more weight and speed it can push way more easily then an object that has less weight and/or speed. I'm also trying to create this without naming the objects so that I can create new object and give them the same parent/code and because of that they should behave the same.
This is my code so far (in step):
Code:
///Pushing stuff
if place_meeting(x+hsp,y,obMovable){
//mobov is the other object(s)
mobov = instance_place (x+hsp,y,obMovable);
//when less weight object pushes heavier objects
pushingF = mobov.weight / weight;
if (pushingF > 1) {
mobov.hsp = (mobov.hsp + hsp) / pushingF;
}
//same weight
if (pushingF = 1) {
mobov.hsp = (mobov.hsp + hsp);
}
//bigger pushes smaller objects
if (pushingF < 1) {
mobov.hsp = (mobov.hsp + hsp) * (1-pushingF);
show_debug_message("WOEKA");
}
/* A failed variant.
force1 = weight * hsp;
force2 = mobov.weight * mobov.hsp;
force3 = force1 + force2;
while(place_meeting(x+sign(hsp),y,obMovable)) {
hsp = force3 / weight;
show_debug_message(force3);
}
*/
//Don't go through the objects
while(!place_meeting(x+sign(hsp),y,obMovable))
{
x += sign(hsp)
}
hsp = 0;
}
I've also tested some things. I can't move the smaller object because of this code:
hsp = dir * -Espeed + fhsp
dir = direction
Espeed = extra speed
fhsp = friction speed
//shouln't matter though.
Before this code alot of different code is being run to see what dir, Espeed and fhsp is. After the code it just tests for walls and does:
x += hsp;
If I remove the whole hsp = di... then I'm able to move the smaller object although the smaller object doesn't work though.
I would really appriciate it if someone could help me with this.
Thank you in advance
I would also want to create a vertical version of this but that will come after I've completed this code.
[Note]: I,m still a beginner at game maker and english isn't my native language. Thanks for understanding
Last edited by a moderator: