- Home /
My Rigidbody can stick/hold walls
When I jump into a wall, and hold the button in the direction of the wall, my rigid body character can hold/stick to the wall for a bit. Here is my code (And no switching to character controller is not an option)
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Controller : MonoBehaviour { public float moveSpeed; public float jumpSpeed; public float hitDistance; public bool isGrounded; public float airTime;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void FixedUpdate ()
{
transform.rotation = Quaternion.identity;
transform.Translate (Input.GetAxis ("Horizontal") * moveSpeed * Time.deltaTime,0f, 0f);
if (Input.GetAxis ("Horizontal") != 0) {
if (moveSpeed < 10) {
moveSpeed += 0.1f;
}
}
if (Input.GetAxis ("Horizontal") == 0) {
if (moveSpeed > 5) {
moveSpeed -= 1;
}
}
if (Input.GetAxis ("Jump") == 1) {
airTime += 1;
}
if (Input.GetAxis ("Jump") == 0) {
if (airTime > 0) {
airTime = 0;
}
}
if (airTime < 60)
{
transform.Translate (0f, Input.GetAxis ("Jump") * jumpSpeed * Time.deltaTime, 0f);
}
}
}
if someone could fix this it would make my week!
This is normal. To avoid it, you have to use physics materials for the wall and/or rb with decreased friction.
Your answer
Follow this Question
Related Questions
Rigidbody causes ragdoll character to fly 4 Answers
Rigid bodies pushable 2 Answers
Huge physics 2D bug, need help with a work around. 0 Answers
How do you add a fixed joint to a first person controller 1 Answer
Player Rotation while walking on wall 0 Answers