- Home /
Intersecting into inner corners of walls, when walking into them.
Hi,
I have a capsule as a player and a mesh collider as a level... The creases in faces on the level mainly consist of right angles. When I walk into an inner corner of the room, my character intersects? I have no idea what is going on, and I really could use some assistance. I used this bit of code to move my character, and my fixed framerate is 100FPS.
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
private float mouseX;
private float mouseY;
public float xSensitiv;
public float ySensitiv;
public float jumpForce;
void FixedUpdate () {
if (Input.GetKey (KeyCode.W))
{
GetComponent <Rigidbody> ().position += transform.forward * speed * Time.deltaTime;
}
if (Input.GetKey (KeyCode.A))
{
GetComponent <Rigidbody> ().position -= transform.right * speed * Time.deltaTime;
}
if (Input.GetKey (KeyCode.S))
{
GetComponent <Rigidbody> ().position -= transform.forward * speed * Time.deltaTime;
}
if (Input.GetKey (KeyCode.D))
{
GetComponent <Rigidbody> ().position += transform.right * speed * Time.deltaTime;
}
mouseX += Input.GetAxis ("Mouse X") * xSensitiv * Time.deltaTime;
GetComponent <Rigidbody> ().rotation = Quaternion.Euler (0, mouseX, 0);
mouseY -= Input.GetAxis ("Mouse Y") * ySensitiv * Time.deltaTime;
mouseY = Mathf.Clamp (mouseY, -90, 90);
Camera.main.transform.localRotation = Quaternion.Euler (mouseY, 0, 0);
if (Input.GetKey (KeyCode.Space) && Physics.Raycast (transform.position + Vector3.down * 0.875f, Vector3.down, 0.25f))
{
GetComponent <Rigidbody> ().velocity += Vector3.up * jumpForce;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to allow collisions on a Child of a Non Kinematic RigidBody ? 1 Answer
Collider question 0 Answers
Rigidbody stuck in colliders when moving and ricosheting. 0 Answers
OnCollisionEnter but have colliding object not move the object it collides with 1 Answer
handling collision with two objects of the same tag 1 Answer