- Home /
Unexpected behavior from bouncing sphere
Hi, I'm playing around with some physics in unity. I've created a sphere and I am using the AddForce on it to move it along the x and y axis like so:
void Start () {
position = transform.position;
ball = GetComponent<Rigidbody>();
ball.AddForce(transform.right * xForce);
ball.AddForce(transform.up * yForce);
}
Once the ball hits the ground and starts bouncing, it's like a force is added to it on the z axis. You can see the behavior here: https://gyazo.com/aa80b05e0129c00dc925d1dc7891715c
I don't understand why this is happening. I wanted to the ball to bounce straight towards the red cube. Can anyone explain? I don't know if it matters, but I have 0 dynamic, 0 static, 0 bounciness physic material on my terrain and 0, 0, 0.8 on my ball.
Hi, is your ball inside the ground? Try moving it upward so that it rests slightly above it. -Greg
Hi Greg, thanks for your reply. I did what you told me to but i didn't change anything. However, I have tried changing the mass of the ball which changed the behavior. When I set it to 0.5 ins$$anonymous$$d of 1, the ball is now able to bounce once the way i want it to, but on the second one it inexplicably bounces to the left, along the z-axis. Here is a gif that shows it.
This is very bizarre. What are you using for your ground? Is it perfectly flat?
Answer by corpsinheretoo · Sep 28, 2018 at 02:53 AM
I am not sure what is going on. But try using Vector3.right and Vector3.up.
From Unity Docs:
Unlike Vector3.up, Transform.up moves the GameObject while also considering its rotation.
I am not sure why this would make a difference in your case but let us know if it works :).
***Update: Solved (probably). This took a lot of research for what seemed like a simple problem. Even a smooth terrain is made up of a bunch of triangles. I am guessing the ball is interacting with the seams. Settings>Physics>Default Contact Offset = 0.5 (default is 0.01) fixes this problem for me. I am not sure what repercussions there may be later in your development of your game though! Good luck and hope this helps.
You are welcome to send me your project (corpsinheretoo at gmail dot com) - I really want to know what is going on :)
I have not received an email :( (spam folder has been checked) corpsinheretoo@gmail.com
Alright, thanks for taking your time to look into this issue. So, would you recommend that I use a cube or the terrain moving forward?
That really depends on what you are trying to make! That is probably getting too off-topic for this thread but you are welcome to email me if you would like to discuss your project specifics more.
Did you get to what's the issue? I'm really curious what's this about
I don't know this solution work or not but I have to mention one thing that changing some variable in setting will affect all project (in this case is the physics system of your project), it will (maybe can) simply solve this bouncing problem but the other part of your game (which using the unity physic system will take effect from this setting too), so make sure you already discuss with your $$anonymous$$m before change this setting. So let say, if this just a practice system, then it won't be a large problem but if this is a product, I'm sorry to say that this may be a bad solution. :(
Your answer
Follow this Question
Related Questions
Sphere vs Capsule collider collision resolution 0 Answers
Sphere behaves strange by jumping on diagonal Plattforms or at terrain 0 Answers
re-orienting velocity 1 Answer
AddForce to sphere 1 Answer