|
Hi, I am trying to write code to cause a ball to bounce off of the walls of an oval shaped arena. I dont want to use the built in physics engine because that dose a bunch of other things that I do not need. I am using the variables of xDirection and zDirection as the values of its x and z speed as well as using the value velocity for it's total speed. I figure I need the program to calculate the normal of the surface I hit and then somehow "flip" my xDirection and zDirection over that. I am not really sure how to proceed though. If anyone can help me to get this work it would be greatly appreciated, my math skills seem to be failing me and I can't seem to find all the proper info online (I must not be looking up the right things). EDIT: OK so I got something working now. I am at least able to draw the correct lines of where it should go, except that after the first bounce it starts behaving weird, and going bounceing nearly back on itself, can anyone help me figure out why?
(comments are locked)
|
|
The Vector3.Reflect example in the docs is terrible, the worst possible - this function is intended to reflect vectors, not positions. I would use a Vector3 as the velocity, and always zero its y component to avoid small errors that could accumulate and make the object "escape" from the horizontal plane. I would also use FixedUpdate, because collisions are detected in the physics cycle. My script would be something like this: Anyway, you may have weird direction problems because Translate doesn't process collisions correctly - the rigidbody just "appears" inside a collider, and receive the "penalty force", which may not be in the correct direction. Thank you sooo much. it works like a charm.
Dec 20 '11 at 05:19 AM
skail
This is old as hell, but just saved my sanity trying to solve a problem similar to this.
Jan 27 at 01:06 AM
cj_coimbra
(comments are locked)
|
