Weirdness in corners

I’ve got some weirdness going on with the colliders

It moves around pretty normally, colliding with the walls N/S E/W…but there’s some weirdness, when it goes into the corners, and I let go of the wasd keys, the player seems to just move off to the right or left, or down or up…

Video above.

Any ideas?

Hi,

Thank you for your video. Unfortunately, I don’t know what I am supposed to see. Everything looks normal to me. Could you please point me to the mark in the video? When exactly are you releasing the WASD keys?

Bear in mind that the physics simulation moves your player during runtime. If your player gets pushed into another collider, the physics simulation calculates the collision and tries to push the player collider out of the other collider. That could lead to funny results in some cases.

Hi Nina thanks for the reply. I am pushing W and D to get it to go into the corner and then release at 16s into the video. At which point the player moves over to the left with no keys pressed.
Then again at 23s

I was wondering if it’s something to do potentially with how my player is set up (three capsules with the rigid body on a group)

Is the Rigidbody attached to the parent?

And how do you you move the player via code? Do you manipulate transform.position directly or use the transform.Translate method? If so, I’d suggest to move the player via the Rigidbody with the AddForce method. Look it up in the API. There is an example. If you understand it, you will certainly be able to remove the current code and replace it with the AddForce method call.

The next thing you could do is to select all non-moving game objects with a Collider component and enable “Static” in their respective Inspector. Do not do that for game objects that are moving during runtime. By setting the non-moveable game objects to “static”, you tell the simulation that these are not supposed to be moved.

You could also add a Physic Material to the ground and/or the player. Increase the friction a bit.

And last but not least, you could slightly increase some values in the Physic Settings. This will could have a noticeable negative impact on the performance, though, so be careful and test your game.

Thanks for the suggestions. I’ll take a look and get back to you (when I get chance to get back to the course later this week)

Really enjoying this course so far

Rigidbody is on the parent, mover script is on the parent
Constraints on the rigid body are Rotation Freeze XYZ, Position Freeze Y
The parent floats slightly above the ground so there should be a friction between the player and the ground.

Adding in some Debuging into the update frame, once the keys are released, there’s no more input. So the movement isn’t coming from input getting stuck in or something.

Movement is being done via, transform.Translate()

Adding Static to the walls and plane didn’t make any difference

Ok, So looking into the AddForce function is an interesting call.
Logging out Rigidbody.velocity I think I can see I think what’s happening now.
When the player is pushed into the corner, there’s a force applied to the player on the X or Z axis in the opposite direction. This force is then stuck on the player until they hit the opposite wall.
Because of using transform.Translate this force is never removed.

using Rigidbody.AddForce() is not a bad idea, but it certainly feels like the player is ice skating around, which is probably not the feel I’m going for or expecting here.

Perhaps setting the force back to 0 before translating, or adding force miight do the trick :thinking:

ETA: rb.velocity = new Vector3(0,0,0); seems to have done the trick

Neither the ground nor the player have got friction. What you could try is to create a Physic Material, increase the friction value and assign it to the player and/or the ground.

However, if you found an alternative solution for your problem, that’s perfectly fine. :slight_smile:


See also: