Unity Camera Bounces with Sphere Animation when trying to apply gravity with Rigidbody - unity3d

I have an empty Object that has, among other things, a third and first person camera, and a sphere with a bouncing animation attached to it. I'm try to get it so that the sphere experiences gravity, but I'm having a lot of problems.
What I want is gravity on my sphere and the camera to not bounce with the ball.
Here a couple scenarios I've tried, and their outcomes:
1) When I attach a rigid body to the the Sphere (child of the empty Object) with apply root motion true or false, my character experiences no gravity. The ball bounces, but the camera follows the ball without bouncing with the ball. It also follows if i press the space button (to jump) The whole problem is i need gravity to fall back down when i jump. Right now i just go up.
2) When I attach a rigid body to the empty object (the parent), I gain gravity, but now my camera bounces with the ball, and if the ball tumbles and rotates, the camera rotates with it.
Is there a way to get the best of both worlds?
i.e: Ball experiences gravity, but the camera does not. The camera simply follows around the ball from first or third person view without bouncing.
Thanks so much

For me, I would like to create a Vector3D variable to record the offset between the ball and the camera. And you simply add the offset to your camera each time so your camera can chase the ball without bouncing with it.
For example:
Vector3D offset = cameraPos - ballPos;
//...
CameraPos = ballPos + offset;
If you don't want the camera moving with ball's gravity, you can block the change of Y axis.

Related

Floor affects ball force direction

I'm creating a pool game. The ball has a trajectory direction and I move the ball using AddForce. My problem right now is if the ball is touching the floor it's direction will go a little offcourse while if it doesn't touch the floor the direction is pretty accurate. What can be the cause of this? Btw, I have set the angular drag and drag to 0 same as friction
Make sure the floor is using a box collider and not a mesh collider, in case maybe the mesh has some deformities. Check the same for the billiard balls that they are using sphere colliders. It also sounds like maybe the floor could be at a slight angle, so be sure to check the rotation of its GameObject as well as all its parents in the hierarchy.

Capsule Collider doesn't move smoothly

I have some issues using CapsuleCollider and RigidBodyController in a Player GameObject in Unity.
Using a CapsuleCollider as collider for the player, I noticed that the player doesn't move like a capsule or a sphere (in other words, I want that the movement should be like a rolling ball, with no stuttering), but its movements like more like a box pushed, with stops and starts, that make some little oscillations of the camera.
Any ideas, solutions or tips?
realy that is all based on how your moving the object, and the rigidbody2D settings of the object, I think using physics forces would roll your character like a ball or capsule, however just setting a velocity wont.

How to move an object without going through colliders

I'm using Unity and i am doing a pong game. I would like to be able to move the paddles with the mouse key. I have tried just moving their position but that of course will simply "teleport" them through the colliders along the edge of the playing field. I tried using addForce() and making the rigidbody fixed in the x position, however, what happens is when the ball hits the paddle, it pushes it and the paddle snaps back. All of the ball's energy is lost (there is gravity in my game). How can i move this box collider but not let it over lap other box colliders while moving? Thanks!!!
Your paddle should be a kinematic (IsKinematic parameter) rigidbody (attached RigidBody2D) collider while the edges should just be a static collider. But, you should control the limits/edges of paddle movement within your script.
If you do things this way, your ball will naturally bounce of the edges and off your paddle. If, however, you want the ball to pass through the edges but notify you of doing so (e.g. lose condition), you should make the edges a static trigger collider (IsTrigger parameter).
Here's a detailed list with all interactions between different types of colliders: http://docs.unity3d.com/Manual/CollidersOverview.html. The messages generated are passed via 2 different functions: OnTriggerEnter2D and OnCollisionEnter2D.

Unity 3d: Prevent Rigidbody from Falling Over

I have a 3d object (army man) that I added a RigidBody to. I have a Gun set up that shoots bullets at the army man --- when a bullet hits it, I want it to fall over. Now I have an issue where as soon as my game starts, my 3d object slowly falls over without any user interaction. I set X and Z freeze positions on the RigidBody but it still falls over. IF I set to freeze on Y position, my 3dObject will not fall over but then if I shoot the army man, it will just spin and not fall over. I attached a screenshot to show all my settings.
Your Collider's mesh is obviously standing on a point and is very unstable looking. Either give him a BoxCollider, or make a tall rectangle, attach a Collider to it and a RigidBody, and make the army man mesh a child of it. Remove all colliders and RigidBodies from the army man mesh.
In the rigid body you also have the option to freeze rotation around a certain axis:

Sprite Kit physicsBody loses consistency during rotation - zrotation

I have this classic situation of a pinball game
All objects are physicsBody with rights collision masks and so on.. they collide perfectly.
The problem is that they only work when they are static...If I try to rotate a paddle on its anchorpoint, there is no collision with the ball and the ball falls down, passing through the paddle.
I thought it was a problem of speed but I think that during the rotation the physicsBody simply doesn't work.
Do you have suggestions?
Thank you so much.
That's exactly the problem you get when rotating a static body, it's not going to act physically correct.
For example static bodies have no force, no velocity - if you move or rotate it, it will just be there at the new position and new rotation without pushing any dynamic bodies around. Only if a dynamic body now happens to be intersecting with the static body will the physics engine try to resolve the collision, usually in a brute-force manner (aka "get me outta here").
Therefore the paddle has to be dynamic if you want it to move, accelerate and spin the ball. Both paddle and ball may need to have continuous collision detection enabled as to not lose any precision in the paddle motion applied to the ball, and vice versa.