RigidBody FPS Controller(standard assets) gets stuck on mesh colliders
I imported a mesh I had made from Blender into Unity (.dae format). The mesh had a ramp going up to a second floor, the ramp is at a 45deg angle. When the RigidBody FPS Controller from the standard assets tried to walk up the ramp it slow down to a crawl and would occasionally slide back down. It would also get stuck in the corner of the mesh especially after it slid down the ramp. The other SA Fps controller did not have any problems, But I needed it to react to physics for the game so I'm unable to use it. I don't believe it is sliding/ slowing down due to friction, or a lack there of because I tried using a variety of physic martials on both the controller and the mesh to no effect. The problem could not be replicated using the other collider types. I've seen similar problems from other people but no solutions were posted.
By the way, I don't know the glitch in your project, sorry.
Answer by Viriato · Jun 05, 2017 at 08:26 PM
Just set the "Shell Offset" variable to 0.1 in the "Advanced Settings" of the "Rigidbody First Person Controller" script.
Answer by Coleclaw199 · May 16, 2017 at 08:28 PM
You should probably not use the built in FPS controllers, so here is a simple movement script and a mouse look script. By the way, the player needs a character controller, and these scripts are aren't tested.
Movement
using UnityEngine;
public class Player_Movement : MonoBehaviour
{
private float jumpSpeed = 8.0F;
private float gravity = 20.0F;
private float speed = 10.0F;
private Vector3 moveDirection = Vector3.zero;
private CharacterController controller;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
CheckForWalk();
CheckForSprint();
}
void CheckForWalk()
{
// Is the controller on the ground?
if(controller.isGrounded)
{
// Feed moveDirection with input.
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
// Multiply it by speed.
moveDirection *= speed;
// Jumping.
if(Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
// Applying gravity to the controller.
moveDirection.y -= gravity * Time.deltaTime;
// Making the character move.
controller.Move(moveDirection * Time.deltaTime);
}
void CheckForSprint()
{
if(controller.isGrounded && Input.GetKey(KeyCode.LeftShift))
{
speed = 11.0F;
// Feed moveDirection with input.
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection (moveDirection);
// Multiply it by speed.
moveDirection *= speed;
// Jumping.
if(Input.GetKey(KeyCode.LeftShift))
{
moveDirection.y = jumpSpeed;
}
}
else if(!Input.GetKey(KeyCode.LeftShift))
{
speed = 10.0F;
}
}
}
Here is the mouse look.(Re$$anonymous$$der: these are not tested.)
using UnityEngine;
[AddComponent$$anonymous$$enu("Camera-Control/Smooth $$anonymous$$ouse Look")]
public class Player_$$anonymous$$ouseLook : $$anonymous$$onoBehaviour
{
public Vector2 clampInDegrees = new Vector2(360, 180);
public Vector2 sensitivity = new Vector2(2, 2);
public Vector2 smoothing = new Vector2(3, 3);
public Vector2 targetCharacterDirection;
public Vector2 targetDirection;
private Vector2 _mouseAbsolute;
private Vector2 _smooth$$anonymous$$ouse;
public GameObject characterBody;
public bool lockCursor;
void Start()
{
targetDirection = transform.localRotation.eulerAngles;
if(characterBody)
{
targetCharacterDirection = characterBody.transform.localRotation.eulerAngles;
}
}
void Update()
{
Cursor.lockState = CursorLock$$anonymous$$ode.Locked;
var targetOrientation = Quaternion.Euler(targetDirection);
var targetCharacterOrientation = Quaternion.Euler(targetCharacterDirection);
var mouseDelta = new Vector2(Input.GetAxisRaw("$$anonymous$$ouse X"), Input.GetAxisRaw("$$anonymous$$ouse Y"));
// Scale input against the sensitivity setting and multiply that against the smoothing value.
mouseDelta = Vector2.Scale(mouseDelta, new Vector2(sensitivity.x * smoothing.x, sensitivity.y * smoothing.y));
_smooth$$anonymous$$ouse.x = $$anonymous$$athf.Lerp(_smooth$$anonymous$$ouse.x, mouseDelta.x, 1f / smoothing.x);
_smooth$$anonymous$$ouse.y = $$anonymous$$athf.Lerp(_smooth$$anonymous$$ouse.y, mouseDelta.y, 1f / smoothing.y);
_mouseAbsolute += _smooth$$anonymous$$ouse;
if(clampInDegrees.x < 360)
{
_mouseAbsolute.x = $$anonymous$$athf.Clamp (_mouseAbsolute.x, -clampInDegrees.x * 0.5f, clampInDegrees.x * 0.5f);
}
var xRotation = Quaternion.AngleAxis(-_mouseAbsolute.y, targetOrientation * Vector3.right);
transform.localRotation = xRotation;
if(clampInDegrees.y < 360)
{
_mouseAbsolute.y = $$anonymous$$athf.Clamp (_mouseAbsolute.y, -clampInDegrees.y * 0.5f, clampInDegrees.y * 0.5f);
}
transform.localRotation *= targetOrientation;
if(characterBody)
{
var yRotation = Quaternion.AngleAxis(_mouseAbsolute.x, characterBody.transform.up);
characterBody.transform.localRotation = yRotation;
characterBody.transform.localRotation *= targetCharacterOrientation;
}
else
{
var yRotation = Quaternion.AngleAxis(_mouseAbsolute.x, transform.InverseTransformDirection(Vector3.up));
transform.localRotation *= yRotation;
}
}
}
Answer by master_rigel · Jul 07, 2018 at 02:23 PM
Just set the "Shell Offset" variable to 0.01 in the "Advanced Settings" of the "Rigidbody First Person Controller" script.
Setting values greater than this, may create a gap between the controller and the colliding object.