Don't move on collision
by Andrew Deters · in Torque 2D Beginner · 11/11/2014 (11:32 am) · 8 replies
I have a player controlled object that other objects can bounce off, but I do not want the player object to move from the collisions. What setting can I put in the creations of ether object to make sure the player object does not move from the collision with the other object?
Or in other words, what has replaced these settings?
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionPhysicsSend = "0";
CollisionPhysicsReceive = "0";
Or in other words, what has replaced these settings?
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionPhysicsSend = "0";
CollisionPhysicsReceive = "0";
#2
11/11/2014 (1:24 pm)
You might also be able to add some OnCollision functions to set the linear velocities to 0 for specific objects based on class.
#3
%PlayerObj.setBodyType("Kinematic");
But now the blocks I set up to keep the player object in bounds no longer stop it from leaving the screen.
At least it does not move when the other object bounces off from it.
11/11/2014 (1:34 pm)
I added this to the player object.%PlayerObj.setBodyType("Kinematic");
But now the blocks I set up to keep the player object in bounds no longer stop it from leaving the screen.
At least it does not move when the other object bounces off from it.
#4
Do the blocking objects have "static" bodies?
{EDIT}
Nevermind - Kinematic bodies do not collide with other kinematic or static bodies.
You may be able to use a sensor to mark the bounds and simply invert the player object's velocity vector if it leaves the sensor.
11/11/2014 (2:39 pm)
Oh, well, of course - the blocking objects can no longer apply forces to the player object. Hmm....Do the blocking objects have "static" bodies?
{EDIT}
Nevermind - Kinematic bodies do not collide with other kinematic or static bodies.
You may be able to use a sensor to mark the bounds and simply invert the player object's velocity vector if it leaves the sensor.
#5
EDIT
Its working to an extent, but is a bit off. The player object is moved on setLinearVelocityY or X, and because of the variable speed it may move further or lesser before the next update stops it. Will still work on it.
11/11/2014 (3:10 pm)
I was working on doing an if inside the objects movement functions to stop movement outside of a range. EDIT
Its working to an extent, but is a bit off. The player object is moved on setLinearVelocityY or X, and because of the variable speed it may move further or lesser before the next update stops it. Will still work on it.
#6
Wouldn't it be easier to set player.setCollisionCallback(1);
player::onCollision(%this, %object, %collisionDetails)
check for player from this and object and react.
OR make your player density higher and the other objects less? Just have to apply more force to move player around.
11/13/2014 (3:02 pm)
As stated above,Wouldn't it be easier to set player.setCollisionCallback(1);
player::onCollision(%this, %object, %collisionDetails)
check for player from this and object and react.
OR make your player density higher and the other objects less? Just have to apply more force to move player around.
#7
Update: 10+ minutes of constant bouncing and the player object has not move a single pixel. Thanks again to all.
11/13/2014 (3:39 pm)
I am now testing setting the density very high, and so far it works exactly as I want it to. Thanks. Update: 10+ minutes of constant bouncing and the player object has not move a single pixel. Thanks again to all.
#8
I'm still learning but I found something very handy for player movement.
I used fish tote was my base but I found my guy movement not update after hitting a wall, he'd follow the new path if I held the key down.
This code below fixed that without having to schedule tons of movement update checks!
make sure callbacks are on for player object. maybe check if it's your player too.
If you need the control movement code, let me know.
11/16/2014 (1:42 pm)
Awesome to hear!I'm still learning but I found something very handy for player movement.
I used fish tote was my base but I found my guy movement not update after hitting a wall, he'd follow the new path if I held the key down.
This code below fixed that without having to schedule tons of movement update checks!
make sure callbacks are on for player object. maybe check if it's your player too.
function Player::onEndCollision(%this, %object, %collisionDetails) {
// update player movement
%move = %this.getBehavior(PlayerControlsBehavior);
%move.updateMovement();
}If you need the control movement code, let me know.
Torque Owner Richard Ranft
Roostertail Games
Specifically:
So, in theory you could make your player object a kinematic object. This should prevent the object from reacting to forces (i.e. collision responses) - but you'd have to set all of your velocities directly instead of applying forces to move it.