Hi, is it possible to check if one body collides with another before simulating any physics?
The problem is that I'm writing a strategy game which has all kinds of vehicles and soldiers. All of this is simulated by means of box2d 2.1a. Both, soldiers and vehicles are dynamic bodies, and it's ok that vehicles can move soldiers when they run into them, but I want soldiers not to be able to move vehicles in any case.
I tried to set soldiers as sensors, but in this case they can walk thru vehicles, which is not good in this case.
I tried to set a negative linear velocity on soldiers when they collide with vehicles. It almost works, but if I click many times, giving soldier a command to walk, it can still gradually move the vehicle.
p.s. Soldiers walks around like this:
Feels like I'm completely stuck, and some help would be really appreciated
The problem is that I'm writing a strategy game which has all kinds of vehicles and soldiers. All of this is simulated by means of box2d 2.1a. Both, soldiers and vehicles are dynamic bodies, and it's ok that vehicles can move soldiers when they run into them, but I want soldiers not to be able to move vehicles in any case.
I tried to set soldiers as sensors, but in this case they can walk thru vehicles, which is not good in this case.
I tried to set a negative linear velocity on soldiers when they collide with vehicles. It almost works, but if I click many times, giving soldier a command to walk, it can still gradually move the vehicle.
p.s. Soldiers walks around like this:
Code:
public function toPoint(x:int, y:int):void { // called on mouse click
_angle = Math.atan2(y - this.y, x - this.x);
_clickPoint = new b2Vec2(x / _ratio, y / _ratio);
_direction = _body.GetPosition().Copy();
_direction.Subtract(_clickPoint);
_direction.Normalize();
_direction.Multiply(_speed);
_direction.NegativeSelf();
_enabled = true;
}
public function update():void { // called on timer
if (isLeader) {
if (enabled) {
_body.SetAngle(_angle);
_body.ApplyImpulse(_direction, _body.GetPosition());
checkDestination();
}
}
}
_angle = Math.atan2(y - this.y, x - this.x);
_clickPoint = new b2Vec2(x / _ratio, y / _ratio);
_direction = _body.GetPosition().Copy();
_direction.Subtract(_clickPoint);
_direction.Normalize();
_direction.Multiply(_speed);
_direction.NegativeSelf();
_enabled = true;
}
public function update():void { // called on timer
if (isLeader) {
if (enabled) {
_body.SetAngle(_angle);
_body.ApplyImpulse(_direction, _body.GetPosition());
checkDestination();
}
}
}
Feels like I'm completely stuck, and some help would be really appreciated