Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
How to implement ricochet?

guest20240329
Guest
Quote
2024-03-29 14:00:28

Hi
Wanna implement ricochet.
How do I do that?


just_in_case
Moderator
Quote
2024-03-29 14:55:06

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.


new object
Guest
Quote
2024-03-29 14:57:21

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.


guest20240329
Guest
Quote
2024-03-29 17:25:51

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


new object
Guest
Quote
2024-03-29 18:00:21

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.


okeoke
Registered User
Quote
2024-03-29 18:02:09

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.


guest20240329
Guest
Quote
2024-03-29 20:22:33

Thank you!


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inte?national" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact