Can I somehow find out the collision vector? I need to find out with what force 2 objects collided
If you use a physics engine, you can check the new linear/angular velocity of the physics body
May I have a little more detail? I guess I should have described my task in more detail. There is a game, the car drives and knocks the little men. If a collision occurred between a man and a car, then he is shot down. But sometimes a car only slightly affects it and in fact it should not be shot down. I thought it would be more correct to judge whether a person is hit by the impulse of a collision.
How can linear and angular speed help me if it is constantly equal to some value, since objects are moving?
So you have a car, and N little men. For each collision of the car and a single little man, you check the linear velocity of the little man after the collision, and define a threshold for the length of this vector from which to decide if the little man is shot down.
I assume shot down means - disappear from the scene. If you use a physics engine you can actually make the person fall down on different collision properties using (mainly) the mass of parts of the objects. The last sentence can be a bit confusing - think about a chess piece with something heavy at the bottom. The heavier it is, the harder it is to make it fall if you throw a ball towards it. The ball’s mass, speed, direction, will all influence the drop. A physics engine works the same.
I think speed testing is not the best option. A little man is a box over which a skeleton is pulled. For realistic movement, each person runs after a sphere moving in front of him (steering behavior).
The speed with which the box moves is calculated as follows:
That is, the box is constantly changing linear speed. Therefore, depending on the strength of the collision, I need to decide whether to stop the movement of the box or not
I don’t know the use case, but a car crashing into people will probably bring the people to a higher velocity than they were at I would expect a person that their velocity changed so drastically to be eliminated.
If you need something more advanced than that - what engine are you using? Care to share a demo?
Ammo. Try to knock down man
http://test3.avior.by/site/car1/build/index.html
It is a very light and little car compared to the big people Not exactly the scenario I imagined. But still, I would use velocities. The velocity of both bodies (before and) after the collision can tell you a lot about it. It does depend on your definition of velocity, person, and car
I don’t know Ammo that well to tell you whether or not this function exist, maybe @Cedric can be more of a help here
I think you can add a function for collision callack but I can put hands on it.
Then, I’d check the linear velocity and the direction of both objects.
If the dot product of both linear velocity is almost 1, then I’d do nothing. If the dot is <0, then the collision would be brutal.
I don’t understand a bit how the scalar product will help here. Why, if the work is almost equal to 1, nothing needs to be done? it just shows that 2 bodies move in the same direction
Maybe you can find collision response thanks to these callbacks:
I already use collide callback and there I calculate whether the body should stop in a collision, the question is different. How does a scalar product show the stiffness of a collision of bodies?
the value abs(dot(velocity1, velocity2)) is proportional to the difference in magnitude of the vectors. if 1 then the velocity is almost the same independently of direction.
I calculate the scalar product as follows:
const scalar = car.physicsImpostor.getLinearVelocity().x * body.physicsImpostor.getLinearVelocity().x + car.physicsImpostor.getLinearVelocity().z * body.physicsImpostor.getLinearVelocity().z
But in a hard collision, the value is also equal to 1.
Almost always, this value is of great importance, for example, 50. I made sure that the men did not move, the little man was slightly consulted by the machine and the value was 50
And if you do a vector delta then compute the length of the result:
x = car.physicsImpostor.getLinearVelocity().x - body.physicsImpostor.getLinearVelocity().x;
y = car.physicsImpostor.getLinearVelocity().z - body.physicsImpostor.getLinearVelocity().z;
const scalar = Math.sqrt(xx + yy);
http://test3.avior.by/site/car1/build/index.html
Please open the console and try to bring down the man. The scalar is displayed in the console. It’s still not what it should be and I don’t understand how to use the obtained value
What do you want to achieve actually? What do you want to use the value for?
I need to understand how tough the collision was. If the car touches the body slightly, then it makes no sense to stop it.
ok, then I stick with this solution:
x = car.physicsImpostor.getLinearVelocity().x - body.physicsImpostor.getLinearVelocity().x;
y = car.physicsImpostor.getLinearVelocity().z - body.physicsImpostor.getLinearVelocity().z;
const scalar = Math.sqrt(xx + yy);
a value of 0 means the car and body have the same speed. The greater the value, the greater the collision force.
Sorry, but I think this is a bit wrong) Because in such calculations the contact area of ​​the bodies is not taken into account. That is, the car can only “wipe” the body from the side