Vertical position moves on its own on a platform

Hello, I am creating my first video game, I intend to finish it and publish it on Steam when I finish it, but I have run into a problem that I cannot solve.

I was finishing up with the coastal/corner configuration and I found that many times the character when reaching the corner would go up a little, being very ugly.

Investigating I realized that the vertical position of my character moved even though he was only moving horizontally, this causes that when he is not touching the ground, if he is “going up” even very little, it is thought that I am jumping and causing the sensation ugly that I commented before.

I have tried to remove and put the “Used By Composite” option but it works almost worse removing it.

How could I make the “Ground” totally straight?

I have recorded a video so that the doubt is clearer and you can see how the vertical position is changed on the platform:

It seems you’re looking for some kind of change in Unity settings to fix your issue but you’re using some custom CharacterController whose job it is to move so isn’t the problem there? I mean, it’s that which is determining movement and grounded state.

Being a predominantly English speaking forum, it isn’t helping that the annotations are not in English and I’m afraid the video isn’t clear, at least to me. I’ve watched it several times.

If you’re talking about the floating-point to the Nth decimal place changing in Y then that’s expected. These are essentially fractions of a mm. The physics system is solving the opposing forces of the ground stopping overlaps, gravity pushing it into the ground and the forces you’re applying. This won’t produce an exact Y value; this isn’t a value in pixels or anything.

It sounds like your character controller is too sensitive to changes in Y. Perhaps it’s comparing Y and not a change in Y above a certain threshold.

For grounded state, you are much better check to see if you’re in contact with a collider rather than any specific Y position like this:

The above grounded state is using a single line: PhysicsExamples2D/Assets/Scripts/SceneSpecific/Miscellaneous/SimpleGroundedController.cs at d957391d0a2b70225ffdcaede90f40d679df5d1e · Unity-Technologies/PhysicsExamples2D · GitHub

Thanks for the reply !.

And if I’m talking about the floating-point to the Nth decimal place changing in Y.

Those tenths cause me a problem.

The problem is that in the animator it detects if the speed Y is greater than 0, the jump begins and if it is less than 0, the fall of the jump begins to descend.

If you look when I am NOT on the platform, the Y is linear even in its tenths, but if I am on the left, tenths go up, if I go to the right, tenths go down.

This causes that when I run to the left the character believes that he is starting to jump (since I am raising those small tenths causing the Y speed to rise even if it is very little)

Sorry for my english, I know it’s very bad :frowning:

But this is controlled by your character controller surely so I’m not sure what else to tell you. I don’t see speed indicated anywhere in your video, it says zero in your controller in the video.

1 Like

In the video specifically in the animator you can see the vertical speed that happened to the animator from the controller

I know and as I said above, it’s always shown as zero.

The velocity of the Rigidbody2D is shown in the inspector for Rigidbody2D > Info.

It is expected that small velocities are there.

Make it so that your controller removes small fractional changes around zero.

1 Like

Don’t pay attention to the player controller inspector because the “Vertical speed” field doesn’t work, look at the “animator” field, I just did the rounding you told me about.

In this new video you will see more easily that it is not because of the physics, it is because the terrain is slightly inclined and I cannot understand the problem.

Sorry for my English, I know it will be hard for you to understand me :frowning:

So you’re saying it’s the collider on that corner? Could you explain/show what the collider is there (show the collider gizmos, remove the sprite render part)? All a TilemapCollider2D?

If it’s all a tilemap then I don’t see how a composite would make it worse. Were you using outline mode because this is why users use it. Only physics edges produce continuous surfaces. The EdgeCollider2D or the CompositeCollider2D (in outline) mode produce edges.

1 Like

Hello !,

The issue is that the floor is separated according to its type (Coastal to the right, Coastal to the left, or straight floor).

I need it separated because in the “PlayerController” I detect what kind of ground the character is stepping on to rotate the character in one way or another.

What solution do you propose?.