Unity: Get velocity of Rigidbody despite collision - unity3d

I have an object Box moving towards object Wall with a target-velocity.
When Box hits wall the actual velocity becomes zero. I was expecting due to the collison with Wall for Box.Rigidbody.velocity to be zero. But it is still the target velocity.
I want to know the actual velocity of the Box at all times. During and outside a collision.

Related

Detect collision coming from outside to inside

How can I detect collision coming from outside and not detect collision coming from inside to outside
I have a game when a player fires a bullet it returns after a while like a boomerang. But my problem is that it should NOT detect a collision when the bullet is coming from the player but it should detect collision when the bullet is returning. I've tried oncollisionenter2d and ontriggerenter2d but it's not working
You could check the direction of the bullet and react (or ignore) accordingly. The exact implementation depends on how you are moving the bullet.
If you are using a Rigidbody, you have access to the Vector3 velocity field, which you can multiply with the bullet's distance from the player with Vector3.Dot(). If the result is negative, then the two vectors are pointing in opposite directions (which means the bullet is moving away from the player) and you simply return from the OnCollisionEnter call.

Rate Over Distance Particle System Not Showing - 2D Gameplay

I have bought a particle system pack from the Asset Store of Unity:
Epic Toon FX
Now within my project, I want to use object trail effects for my player spaceship.
So I have added my selected particle system object within the child of player spaceship object.
But I can't able to see any trail when I run my project within Unity editor.
Within the particle system, I have noticed that the emission rate is based on distance.
How to emission this particle system?
That is big question in the mind.
At present, its parent spaceship object is moving.
Your space ship game object must be having a kinematic rigidbody. The problem with rate over distance is that they are not good to go with kinamatic rigidbody. Try setting the type of rigidbody to dynamic with gravity scale to 0. This should help .
Moreover, remember to move the rigidbody by changing its velocity and not the transform. Also set the simulation space to world.
https://answers.unity.com/questions/1291623/particles-rate-over-distance-emission-not-working.html
#Siddharth

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

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.

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: