- Home /
Curve a Ball in 3d space
I'm trying to make a 3d pong game. And i have a problem with the way the ball curves. No matter what the ball will rotate but will not curve in 3d space. Gravity is off and it bounces perfectly, although there is rotation persent, there is no curving.
Does anyone know what kind of script i could use to manualy make the ball curve....im thinking of taking the axis rotation off the ball and then add a force somehow to the direction its rotating.
Answer by Scott 7 · Feb 16, 2011 at 05:22 PM
curve balls do rotation in air, is a somewhat complicated fluid dynamics phenomenon involving Bernoulli's principle, so you will have to code your own physics in this situation. luckily if you don't mind fine tuning it to your liking instead of going for realism, you could put a line like this in some script on the ball.
rigidbody.AddForce( fudgeFactor*Vector3.Cross(rigidbody.velocity,rigidbody.angularVelocity), ForceMode.Force);
Answer by Matt 22 · Feb 17, 2011 at 02:58 PM
What exactly does that code do, like the vector3.cross, etc, so far i have
rigidbody.AddForce(Vector3.Reflect(-rigidbody.transform.TransformDirection(Vector6), theCollision.contacts[0].normal) * mag, ForceMode.Impulse);
Do the codes interfere with eachother? My ball is bouncing like crazy and not really curving. My fudgeFactor is on 10, any higher and theres no control of the ball.
Ive tried with both codes and then each code separatly and its not curving or changing direction while in the "air", my rotation is not frozen. Any other ideas, is there a way to just manually make it curve?
the crossproduct of two vectors returns a third vector with a magnitude equal to the multiple of the perpendicular parts of the vector and whose direction is perpendicular to the other two rays, the order of the two vectors. It sounds like the code is curving the ball since with higher then 10 it goes crazy. What you need to do is go int project settings and speed up the frame rate so that the physics has time to act on the ball in the short time it is between bounces.
Answer by Alex Visan · Feb 18, 2011 at 06:31 PM
Wow thanks, it works fine now. I made the frame rate faster and i realized that i used that vector3.cross on a collision function. I put it in an update function and it works like a charm. Thanks a lot!
another question that i cant seem to find on the internet, is how can i limit my velocity so that way my x and y values stays below 500 and my z value stays below 2000. If made an if statement that just says if all the values are false then go through and add force with my previous code. But once that happens i will go a little higher than my max and it will get stuck bouncing sideways forever
Answer by Leaton · Jun 15, 2018 at 05:09 PM
Check out these links showing how I did this in my project.
http://leatonm.net/unity-tutorial/unity-ball-throw-with-curve-like-pokemon-go/ https://www.youtube.com/watch?v=tgr_ccLnJXk
Your answer
Follow this Question
Related Questions
overlap numbers 0 Answers
A node in a childnode? 1 Answer
Best Looking Unity Game? 2 Answers
Anywhere to find animations? 0 Answers