#Stick to ground

1 messages · Page 1 of 1 (latest)

next rampart
#

Hello, I have an issue where my character should be sticking to the ground, and, while he does, it's like there's some "magnet force" or something that happens when running though slopes.

If I run on a convex surface, my character is no longer "touching" the ground as if he was pulled away from the surface but held back by an elastic rope, even though he's still considered "on ground".

If I run on a concave surface, then he gets a bit into the ground.

The faster I go or the harder the slope, the bigger the effect.

Here's how it looks like, look when he enters the concave part, and then the convex part :

Here time scale equaled 0.5 :
https://gyazo.com/0a9da0aedd586db61a6e11ab81f1551d

Here, it equaled 1 :
https://gyazo.com/0a9da0aedd586db61a6e11ab81f1551d

Also, the values for the groundHit indeed changes instead of always staying the same (the value I'm aiming for is 0.25, and here it can go up to 1.5 and down to 0.05 for example).

Here's the code for the OnGround method :

  public void OnGround() {
    float maxLength = 0.5f;
    if (onGround) maxLength *= Mathf.Clamp(RB.velocity.magnitude / 10f, 1f, 5f);
 
    if (Physics.Raycast(transform.position, -transform.up, out groundHit, maxLength, collisionMask)) {
      Debug.Log("Is on ground");
      Debug.Log("hit dist: " + groundHit.distance);
      RB.position = groundHit.point + transform.up * 0.25f;
      onGround = true;
      return;
    }
    Debug.Log("Is NOT on ground");
    onGround = false;
  }

Thanks for the help !

jaunty glen
#

I would suggest sharing supported video file format like mp4...

low nova
#

What exactly do you mean by a "magnet force"? Like, the player is being dragged towards the ground?

#

Or being pulled along the slope?

next rampart
#

I attached 2 videos in which you can see what happens, it’s really weird. I don’t know how to phrase it better 😦

The player is still considered on ground but it is pulled away from the ground when I get to the top of the slope (the convex part) and into the ground on the concave part

#

Just like if it was attached to some elastic rope that stretch and let it go out a bit while still being attracted to the ground

next rampart