Hi,
I need to add a force to an object in it’s opposite direction, this is for implementing colisions against other objects, I tried a few things but I can’t get it to work.
Hi,
I need to add a force to an object in it’s opposite direction, this is for implementing colisions against other objects, I tried a few things but I can’t get it to work.
You can read the object angle through the expression “MyObject.Angle()”, and the total force angle with “MyObject.ForceAngle()”, but not sure which one you want to use. To add a force to the opposite direction your object is facing it would be:
Add a force to MyObject, angle: MyObject.Angle() + 180, length: 200
The “200” is just for the example, the important point here is the “angle + 180” to get the opposite angle.
Also, in case you need it, you can access the total force length with “MyObject.ForceLength()”.
I tried this lizard, but it works ok when I’m colliding an obstacle from the right, if I collide from the left, the tank gets pulled across the obstacle and stops moving on the opposite side of it.
I’m using:
Add to tank an instant force, angle: tank.angle() + 180 degrees and lenght: 100 pixels
I just need the tank to NOT go through obstacles, maybe I’m trying to implement this the wrong way.
any idea how can I get it to work¿?
UPDATE:
Ok , as usual, I was doing it wrong, I used the " sparate objects" action instead, it achieves what I need but somehow, sometimes it splits the turret from the tank, which are two separate objects, do you know how to fix it, or if there’s a way to “group” two objects so their axis never get split?
Thanks!
The “separate two objects action” modify de objects position (obviously), maybe you’re positioning the turret first and then separate the tank from the walls?, the oden of events should be other way or you’ll get an offset
This is the event I’m using
This is the turret original position
This is the turret position after the tank colllides with anything
I tried switching the order of the actions, I’m not quite sure how to get this to work.
both objects start on the map, I dragged them into the screen from the editor, both objects move at the same speed when pressing WASD, maybe if there was a way to attach or group objects so the turrent woudln’t even move and just go on with the tank I could get it to work, but I can’t manage to do it right.
Not the order of actions but the order of events, where is the event that set the turret position?
You have to put that event after this one. A logical order would be:
This way when you locate the turret it will be placed in the final correct position
Using the “separate two objects” action on both tank and turret sounds unnecessary. If you constantly update the x and y position of the turret to be on the tank (using a point), then however the tank moves (or gets moved) the turret will stay with it.