- Home /
Collision Problem with AVATAR
Hi there I have a problem with my avatar and my map ( imported from sketch up ).
Everytime I slide ( crouch ), my avatar can pass through wall. But when I run, my avatar can detect the collision.
What am I doing wrong ?
Here is my sliding code, maybe it is the problem?
THX
Please help me
public class SliderInputController : MonoBehaviour
{
public float slidingDistance;
public float slidingHeight;
public float slidingSpeed;
public AnimationCurve curve;
private CharacterController characterController;
private CharacterMotor motor;
private float originalHeight;
private Vector3 slideStartPosition;
private Vector3 slideStatDirection;
private Vector3 destination;
private float currentTime = 0.0f;
private bool isCrouched = false;
private bool rightClick = false;
private void Start ()
{
characterController = GetComponent<CharacterController>();
motor = GetComponent<CharacterMotor>();
originalHeight = characterController.height;
}
private void Update ()
{
if(characterController.isGrounded==true)
{
// Detection des touches
if(Input.GetMouseButtonDown(1))
{
//Debug.Log("Crouch");
characterController.height = slidingHeight;
characterController.center = new Vector3(0.0f, -slidingHeight/2.0f, 0.0f);
slideStartPosition = transform.position;
destination = slideStartPosition + transform.forward * (slidingDistance + motor.movement.velocity.magnitude);
destination.y = transform.position.y;
rightClick = true;
isCrouched = true;
motor.canControl = false;
}
if(Input.GetMouseButtonUp(1))
{
//Debug.Log("want to get up");
rightClick = false;
}
// Ici je traite les touches
if(isCrouched)
{
if(currentTime < 10 )
{
currentTime += slidingSpeed * Time.deltaTime;
transform.position = Vector3.Lerp(slideStartPosition, destination , curve.Evaluate(currentTime));
}
if(!rightClick)
{
// Space est relaché
Debug.DrawRay(transform.position, Vector3.up * 2, Color.yellow);
if(!Physics.Raycast(transform.position, Vector3.up, 2))
{
ResetSlider();
}
}
}
}
}
private void ResetSlider()
{
Debug.Log("Is getting Up");
characterController.height = originalHeight;
characterController.center = new Vector3(0.0f, 0.0f, 0.0f);
currentTime = 0.0f;
isCrouched = false;
motor.canControl = true;
}
}
Comment
Your answer

Follow this Question
Related Questions
collision detection fail 1 Answer
2D Collision 1 Answer
Detect Collision on Already Batched Object 0 Answers