# Collisions (ohysics) for Missiles, Bullets, Explosions etc

#73

then any suggestions for determining if a target is behind cover or not? if im to use `SphereCast()`?

#74

Hi,

#75

Ah, but it is not mass times speed: It’s mass times acceleration; a change in speed… and let’s assume the bullet instantly comes to a full stop upon impact.
This also means that when no forces (like gravity, drag or collisions) are applied to an object it will continue at the same velocity (linear and angular), in the same direction. Like an asteroid in deep space.

You could use a spherecast to find the objects that you would then each check with one or several raycasts for possible escaping of the blast.

#76

this raycasts here is the new question, how to do them?
i mean how do i determine the parameters for the raycasts

#77

Go over some of the examples that use raycasts.

#78

Sample using `Octree` raycast:

Similarly you can use these `PhysicsWorld` functions:

#79

update: about the “force” to apply on the hit target to simulate the reaction of the bullet impact, i accidently found this momentum and its conservation principle, so there is
(subscript b means bullet, t means target)

and so the change of target’s velocity
and becuz the mass of both objects and the initial velocity of the bullet when impact are known, the change of bullet’s velocity are determined by game logics, is solvable.

now we can finally & simply do this:

``````Vector3 finalVelocity = target.GetLinearVelocity() + change_of_velocity;
target.SetLinearVelocity(finalVelocity);
``````

im an idiot of logics and math, criticize me if i got anything wrong

#80

The main problem I see is the calling of `SetLinearVelocity`, this is something you want to avoid. Instead apply forces and impulses.

Also, you do not need math to just try out some numbers and (not) see their effect.

#81

i just want the codes to generate the impact automatically so i dont need to provide a random number every time

#82

To simulate a bullet impact I use code like this:

``````hitRigidBody.ApplyImpulse(((StereoApplication)Application).LeftCamera.Node.Direction*10, result.Value.Position);
``````

So 10 times the camera direction. It’s quite a powerful bullet. Spins a ragdoll right around and off it’s feet.

And another example:

``````hitRigidBody.ApplyTorqueImpulse(Vector3.Up * 4);
``````

#83

I would add some mention of Collision Filtering - ie, Collision Group and Collision Mask (the latter is called collision layers in Urho)

#84

the real question there is not if the hit targets are correctly collided or not,
but whether there are obstacles between these targets and the explosion center or not.

#85

You want to determine which object was hit first - a ray cast starts at its origin, and in theory, moves forwards, and you can return the first object that was hit, and determine if it was a wall, or not. Filtering is useful to ignore collisions with things you don’t want included in the result, such as trigger (aka sensor) volumes

#86

im not talking about excluding walls or other non-player related game objects
im talking about how to check if any of the results are actually behind covers

#87

Ray casts only return the first thing that the ray hit - in your case, you will either be told that the ray hit a wall, or it hit a game character, so we can deduce, hey, if my bullet hit the wall, then the character was not hit.

#88

i think you mistook `Raycast()` with `RaycastSingle()`

and Modunung’s reply you replied to had changed topic from bullet detection to explosion detection

#89

Raycast is a general term, I was using it in a general sense. Yes, you want to use RaycastSingle, so you get the closest hit result, you’re not interested in raycasting for multiple objects. I apologize for the confusion.

#90

i think you are actually even more confused

so sad i cant draw, or i will draw some to explain what im really talking about

#91

You want the closest result - if you use Raycast, you’ll need to find which result is closest - RaycastSingle returns the closest result - I’m not confused about that I’ve used many engines, and I’ve used Bullet in my own engines, I’m pretty clear about you wanting the closest hit result, not every hit. Spherecasting is where we tend to want multiple results, but if we wanted to fire a laser beam, we might want to know about all the hit objects.

#92

i think i have finished the topic on bullet detection…

and have moved to that of explosion…