Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Bouncy Bullets
Topic Started: Jan 15 2013, 05:53 AM (234 Views)
From Soy Sauce
Advanced Member
[ *  *  * ]
Hey guys, I was wondering how I could make a gun that shoots bullets that ricochet when they hit walls/ceiling/floor. Like the Judicator from Metroid Prime Hunters:
http://youtu.be/z_GeoRC71BI?t=1m17s
Offline Profile Quote Post Goto Top
 
Reikyrr
Forum God
[ *  *  *  *  *  * ]
You probably want these
Quote:
 
CheckRayIntersection(
ObjectID,
RayOriginX,RayOriginY,RayOriginZ,
RayDirectionLongitude,RayDirectionLatitude,
RoomIndex
)

And
Quote:
 
GetRayTracingNormal(
OutputVectorID
)

And you'll need to use vectors. Look it up in the manual.

The normal points from the intersected triangle to the front. Using that you can calculate bullet ricochet.
~Inspirational quote~
Offline Profile Quote Post Goto Top
 
RonBurgundy
Member Avatar
Forum Borat
[ *  *  *  *  *  * ]
If you can wait, I'll find my hockey game and give you the snippets.
!!! DEFEND POP PUNK !!!
Offline Profile Quote Post Goto Top
 
From Soy Sauce
Advanced Member
[ *  *  * ]
Ooo sounds good!
Offline Profile Quote Post Goto Top
 
RonBurgundy
Member Avatar
Forum Borat
[ *  *  *  *  *  * ]
Couldn't find it. However lucky for you, I found this snippet in an old post of mine.

Code:
 
//THIS WOULD BE FOR DOING BULLETS AS OBJECTS, INSTEAD OF ONLY RAYCASTING.//

//First Do a ray check with the map/level.
ray=CheckRayIntersection(rink.id,x,y,z,rotx,roty)

//***ray < 2 : the vector calculations will only happen if the distance between the bullet
// and ray is less than 2. However, bullets move fast,
// so you may have to change 2 to a higher number.
// Otherwise this may not work accurately or at all***//

//If there is some Geometry being intersected by the bullet...
if ray < 2 and ray > -1 collision = 1;
//So, the bullet collides!
if collision = 1
{
//At this point, the bullet has collided and we need to tell U3D to get
//our new rotation vaules based on this vector.//

//Make a new vector that will handle our new rotation points..
Vector=GetRayTracingNormal(-1);
//New roty rotation
roty = CalculateVectorLatitude(Vector);
//New rotx rotation...you can 45 to this to give a slightly more realistic bounce.
rotx = CalculateVectorLongitude(Vector);
//Free it from memory to avoid a leak
ReleaseVector(Vector);
//Set collision to 0. We done hur.
collision=0;
}
//Finally, move towards its rotation points, before and after it collides.
Move(rotx,roty,speed2)


This wont work accurately, at least not according to physics. But I htink with some adjustments you can get it working that way.

Hopefully this guides you in the right direction.

EDIT: Maybe, MysteriXYZ would have been proud ^_^
Edited by RonBurgundy, Jan 16 2013, 05:24 AM.
!!! DEFEND POP PUNK !!!
Offline Profile Quote Post Goto Top
 
Dr. Best
Member Avatar
Administrator
[ *  *  *  *  *  * ]
The physically correct formula is here:
Posted Image
It can be implemented with two invocations of CalculateDotProduct(), one division and multiplication by two, one invocation of CalculateVectorScalarProduct() and one invocation of CalculateVectorDifference().

Actually the divisor, which originates from the normalized vector GetRaytracingNormal(), is always one, so one scalar product the division can be omitted. You end up with this formula:
Posted Image

(Change the theme of the forum, if you can't read it).
Offline Profile Quote Post Goto Top
 
RonBurgundy
Member Avatar
Forum Borat
[ *  *  *  *  *  * ]
The v is the normalized vector correct? I'am trying to figure out what a is or rather what to put in for a.
!!! DEFEND POP PUNK !!!
Offline Profile Quote Post Goto Top
 
Dr. Best
Member Avatar
Administrator
[ *  *  *  *  *  * ]
v is the velocity vector of your bullet or more generally speaking the vector you want to reflect. It does not need to be normalized. a is the vector you obtain from GetRaytracingNormal() or more generally speaking the normalized normal vector of the plane on which the vector is reflected.

In the following formula the first multiplication-dot denotes common multiplication of real values, the second one denotes a dot product, and the third one denotes a scalar product.
Posted Image

EDIT: The listing of multiplication dots was wrong previously, because I overlooked the multiplication by two. It is fixed now.
Edited by Dr. Best, Jan 17 2013, 02:23 PM.
Offline Profile Quote Post Goto Top
 
RonBurgundy
Member Avatar
Forum Borat
[ *  *  *  *  *  * ]
Thanks for the help Doc.

I'll get this working correctly, and FromSoy if you still need help with this let me know.
!!! DEFEND POP PUNK !!!
Offline Profile Quote Post Goto Top
 
From Soy Sauce
Advanced Member
[ *  *  * ]
Thanks Dr. Best.

@ Ron, I'll try something out, and see what happens.
Edited by From Soy Sauce, Jan 17 2013, 06:25 PM.
Offline Profile Quote Post Goto Top
 
ZetaBoards - Free Forum Hosting
Enjoy forums? Start your own community for free.
« Previous Topic · Questions about Ultimate 3D · Next Topic »
Add Reply