- Home /
Prevent physics shaking
Hi people.. I'm having some problems with physics, my character keeps passing through moving floors/objects.
This (poorly) animation is what I expect:
As you can see in the animation above, the character keeps nice on the floor. Now the reality is this (not animation, used unity):
Here we have two problems:
1. The character is moving to both sides (and jumping), shouldn happen, since the floor where he is standing is not rotating.
2. The character gets into the floor, sometimes he pass through the floor completely. If I increase the velocity of the rotation, it's almost impossible to make the character stand on the ground.
This is a prototype (thats why the sprites are sh**y).
Code - Rotator.cs
public class Rotator : MonoBehaviour {
public float DegreesPerSecond = 80.0f;
void Update () {
transform.Rotate(new Vector3(0, 0, Time.deltaTime * DegreesPerSecond));
// The grund where the player will stand...
Transform block = transform.FindChild("Block");
if (block != null) {
block.localRotation = Quaternion.Euler(-transform.rotation.eulerAngles);
}
}
}
Structure
The rotator is using Polygon Collider, but that Block child (where the player will be) is using Box Collider 2D. Tried to switch from Polygon to Box Collider and still same issues.
I think the player script is irrelevant, since I'm only moving the player to prevent him fall off the screen. I can disable the player script, the issues listed above will happen, the difference is that the character will fall off, so I don't think the player script is the problem.
I bet that this will happen on every moving object/ground, so, there's a way to fix this?
PS. Newbie on unity and game developing.
PS²: English is not my native language.
PS³: Using Unity 5.3 x64.
I was struggling with this as well in a 3D game. But actually - if you think about it for a $$anonymous$$ute - the lower one is more physically correct than the first one where the character is kinda glued to the platform and ignoring inertia.
In the end I don't think you can solve this by using physics. You might have to parent / unparent the character to the platform whenever it touches it or have a script that directly moves the character by the same delta that the platform moved in the meantime (which is my approach).
There are some other posts with solutions to this on here if you search for "platform" or stuff like this.
By the way: Nice post! :)