Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Hi Wanna implement ricochet. How do I do that? |
||||
|
You can try doing a collision check with the bullet then can use either a polyfill of the reflect vector method to reflect the bullet into the different direction, best is to create your own custom bullet. If my memory is not corrupted, I remember @Diaboro aka Xandraa, created something like this for his shooter game in past, so you can ask him to help you out. |
||||
|
To create a ricochet, you can use the direction of the object that needs to ricochet. When it hits something, just move it in the mirrored direction. That's the easiest way to do it. However, you can also utilize velocity or acceleration and the normal of the point where this object hit, creating a more complex ricochet. There are really many ways to create anything, so you need to provide more information about the specific type of ricochet you want. |
||||
|
How to get normal of object face which is in collision with, say, camera? I'd better do some math with face normal and camera direction/velocity vector |
||||
|
Ray Casting: You can cast rays from the point where you want to get the normal in different directions. For example, you can cast rays upwards, downwards, leftwards, rightwards, etc., to cover the surrounding surface. Getting Collision Points: Using the ccbGetCollisionPointOfWorldWithLine function, you can obtain collision points of each of the rays with the world. Computing the Normal: After you have obtained the collision points, you can use these points to compute the normal to the surface. The normal to the surface at a given point will be directed away from the surface. One way to compute the normal is by using tangent rays. For example, for each collision point, you can cast another ray to neighboring points and use their difference to determine the normal. Averaging Normals: If you have multiple collision points and normals, you can average these normals to get a more accurate representation of the normal to the surface in that area. Normalizing the Normal: Don't forget to normalize the obtained normal so that its length is equal to 1. This is important for proper behavior in further computations. |
||||
|
guest20240329 wrote: How to get normal of object face which is in collision with, say, camera? I'd better do some math with face normal and camera direction/velocity vector Well there is really no straight forward way to get a surface normal. Theoretically, you can do the following: 1. Detect collision position which will be on the face of some polygon belonging to the object 2. Now you iterate through all polygons of the object, which bullet collided to, and check if the point belong to a specific polygon. You can find the algorithm here:https://github.com/mikolalysenko.... You can also get the idea how to iterate through the polygons here:https://www.ambiera.com/coppercu... 3. Now you find the normal of polygon (which is not really a polygon but a triangle).https://www.khronos.org/opengl/w... I don't think it will help though, at least I haven't manage to make it work. But if it does for you - please share the code, I would like to also use it in my projects. |
||||
|
Thank you! |
|