Capsule Collider doesn't move smoothly - unity3d

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.

Related

Unity rigidbody always falling when on another rigidbody. (Unity 2D)

I'm relatively new to Unity, I have a player character and a box sprite, I want the box to be movable by the player and for it to fall, so I gave the box a box collider 2D and a rigidbody2D, the box moves fine and the player can move it OK, however whenever the player is touching the box in any way (standing on it or pushing it) the characters Y velocity begins fluctuating uncontrollably making it play the falling animation. Through some testing I found the problem was the player's rigidbody and boxes rigidbody interaction, I don't know how to fix it. Any help would be great thanks
I think u just need to set both the player character and box sprite 's rigidbody2D to dynamic with 1 gravity scale... u can change their mass to manipulate the motion...

In Unity 2D, how do I achieve Non-trigger collsion that doesn't "physically" move the rigidbodies?

I have a bullet game object and an enemy game object.
I want to have the ability of getting the collision point/contact, which's why I think I need the collider of the bullet to not be a trigger collider - this way, I want to have the bullet bounce off the enemy. At times, the bullet will need to bounce off of rectangular objects (not a problem), but I also want the bullet to bounce off of elliptic objects (the problem).
I want the bullet not to "physically" push the enemy, which is why, intuitively, I should set the bullet's collider to be a trigger collider.
When the bullet's collider is a trigger collider, I seemingly don't have a way to implement the bouncing.
But when the collider's not a trigger collider, it pushes the enemy object.
There's no code errors, but I think the code hasn't got anything to do with the problem.
I suspect the problem may have something to do with the Physics Collision Matrix.
EDIT
It seems that raycasting would be the solution to the problem, as Leoverload proposed. My problem became a different problem now, so I'll close off this thread, and open a new one.
Thanks for the help, #Leoverload ! :D
For the position of the hit it's very easy. You must have 2 colliders and 2 Rigidbody and then you can simply add a
Void OnTriggerEnter2D(Collision Coll) and inside it check for the tag : if(coll.compareTag("surface")) and inside you can get the position with collision.transform.position.
The collision matrix on the Physics menu only allows to remove Collision between certain layers, it's useful if you want the enemies not to push eachother!
If you don't want the player pushed you can change the collider to trigger, and destroy the bullet just after the collision with the same method as before with a void OnTriggerEnter2D and the compareTag. In this way it will look like it touches the enemy and explode, but it won't actually touch anything. If you want to add knockback to the player then you could do a simple AddForce based on the direction of the bullet and the work is done!
If you want to avoid the bullet to move walls you can set walls to static and it should work fine

Rigid body doesn't stop moving backwards

I am making a game in unity. I have a tank it's got a rigidbody. I am using transform.translate to move it. When it gets hit by a shot it moves backwards. If use the joystick to move it forward it moves with reduced speed. If I let go of the joystick it continues moving backward.
Please help.
There is not much to go in your question but I'm quite certain you're moving the character with transform.translate (like you wrote) but you have a Rigidbody attached to the GameObject, which uses physics.
So when your GameObject gets hit by a projectile the physics will move it backwards, and you will "teleport" the GameObject with the inputMovement, but that does NOT affect physics.
If you don't want to use physics and are only interested in the collision, you should disable the physics simulation on the Rigidbody compontent.
So go ahead and set the Is Kinematic checkbox in your rigidbody to true.
And, if interested, the value affecting physics is the velocity of the Rigidbody:
GetComponent<Rigidbody>().velocity
You need a Rigidbody on one of the colliding objects, personally I put it on the player but use velocity to handle movement to make sure it works nice with collision physics. When using transform.translate your character will essentially teleport X units every frame, giving the illusion of movement but not actually physically moving. This can make things like teleporting through walls, etc, happen.
So I've told you how to solve your immediate problem, my suggestion is that you re-write your movement logic to use Rigidbody.velocity instead. Your movement seems simple so it's practically just replacing your transform.translate with this:
rb.velocity = joystickInput * speed;

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.

Do I need a rigidbody for gameobject that scales up and down?

I have a beginner-like question. I currently have a gameobject in my scene that scales up and down via animation. It has a Circle Collider 2D on it.
I've seen some tutorials before regarding the performance optimizations of rigidbodies and colliders. I learned that if the gameobject should move in the game, it should have a rigidbody component. Otherwise, a collider component itself is fine for triggers.
Since my game object is kind of moving (because of the endless scale up/down animation), would it be best to put a rigidbody component on it?
I do like to mention that I'm not using any physics movement such as AddForce or anything like that. Hope someone can clear this up.
A gameobject should have a rigidbody component for mainly two reasons, first one is if you are using physics, second one is if you want other colliders to detect a hit/entrance/exit by that gameobject.
From what you described it does not seem like you would need a rigibody on your gameobject, especialy because the movement is only by scale and not by position.
and also, just to clarify, putting a rigidbody component on a gameobject is not a must even if the gameobject is moving. there are different ways to move objects, and rigidbody usually helps in case that the movement should be very realistic and interact with other gameobjects it is colliding with.