- Home /
How can I make my FPS character slide down a angle.
Hi I'm new to Unity and I am following this tutorial for making my character slide down a slope if it is too steep. My script does not have any errors but it just doesn't seem to be doing anything. I would appreciate if someone could tell me what to fix.
#pragma strict
var slideDirection : Vector3; //direction of player slide
var moveDirection : Vector3 = Vector3.zero;
var canAngleSlide : boolean = true;
var speedSlide : float = - 0.0;
var moveSpeed : float = - 0.0;
var slideControllableSpeed : float = 5.0; //speed at where player still has control
var slideThreshhold : float = 0.88; //amount of angle for when the player slides
var slideTag : String = "slide"; //the tag for when the player will slide
@script RequireComponent (CharacterController)
function Start () {
}
function Update () {
}
function AngleSlide(){
if (canAngleSlide) //toggle can angle slide
{
slideDirection = Vector3.zero; //
var hitInfo : RaycastHit; //store hit information
if (Physics.Raycast(transform.position, Vector3.down, hitInfo)) //cast a ray and find objects position and what it hit
{
if(hitInfo.collider.tag != slideTag) //if the collider tag name is tagged with slide then exit out
{
return; //return home
}
if (hitInfo.normal.y < slideThreshhold) //if our normal direction on that slope is lessthen slide threshhold
{
slideDirection = new Vector3(hitInfo.normal.x, 0, hitInfo.normal.z);//the direction for the player to slide, y is set to 0 to keep play
}
}
if (slideDirection.magnitude < slideControllableSpeed) //checks against slide speed, if less then allow some control
{
moveDirection += slideDirection; //this allows for a bit of jerky movement cleanup
}
else
{
moveDirection = slideDirection; //force the slide to go straght down based on slide direction
}
if (slideDirection.magnitude > 0) //if player is sliding
{
moveSpeed = speedSlide; //move player down at slide speed
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Problem sliding down hills (WITH VIDEO) 1 Answer
Travel up and down slopes 0 Answers
[2D] How can I fix player's slope moving problem? 0 Answers
How to rotate the Rigidbody based on the normal of the ground?? 1 Answer
Collision normal angles. 1 Answer