- Home /
Question by
FuzzyQuills · Nov 19, 2013 at 03:20 AM ·
charactercontrollertag
CharacterController high on coffee: Bounces down slopes
Ok, I am trying to stop my character controller from bouncing down slopes - I want it to slide down and remain on the ground like character motor.
Here is my code (If you are going to edit this, please don't remove the combos or flight code!):
#pragma strict
function Start () {
}
var theCuton : GameObject;
var controller : CharacterController;
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
var DeathPos : int;
var Power : int;
var MaxPower : int;
var trail : GameObject;
private var Combo : int = 1;
var ComboEffect : GameObject;
var ComboPoint : GameObject;
private var moveDirection : Vector3 = Vector3.zero;
function Update () {
if (transform.position.y<DeathPos){
Application.LoadLevel(Application.loadedLevelName);
}
if (!Input.GetAxis("Vertical") && controller.isGrounded){
theCuton.animation.CrossFade("Idle");
}
if (!controller.isGrounded){
theCuton.animation.CrossFade("Fall");
}
if (controller.isGrounded){
Power = MaxPower;
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = -Vector3.up;
moveDirection = Vector3(0,0,Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetAxis("Jump")) {
moveDirection.y = jumpSpeed*2;
theCuton.animation.CrossFade("Jump");
}
if (Input.GetAxis("Vertical")){
theCuton.animation.CrossFade("Walk");
}
//attack combos
//this makes sure the combo will work
if (Combo == 1 && Input.GetButtonDown("Action")){
theCuton.animation.Play("PunchLeft");
Combo++;
HUDBar.isAttacking = true;
HUDBar.damage = 5;
}
if (Input.GetButtonUp("Action") && Combo == 2){
Combo++;
HUDBar.isAttacking = false;
HUDBar.damage = 0;
}
if (Combo == 3 && Input.GetButtonDown("Action")){
theCuton.animation.Play("PunchRight");
Combo++;
HUDBar.isAttacking = false;
HUDBar.damage = 10;
}
if (Input.GetButtonUp("Action") && Combo == 4){
Combo++;
HUDBar.isAttacking = false;
HUDBar.damage = 0;
}
if (Combo == 5 && Input.GetButtonDown("Action")){
theCuton.animation.Play("Jump");
Instantiate(ComboEffect, ComboPoint.transform.position, transform.rotation);
Combo++;
HUDBar.isAttacking = true;
HUDBar.damage = 15;
}
if (Input.GetButtonUp("Action") && Combo == 6){
Combo=1;
HUDBar.isAttacking = false;
HUDBar.damage = 0;
trail.particleSystem.Stop();
}
//spin kick!!!
if (Input.GetButtonDown("Action2")){
HUDBar.isAttacking = true;
HUDBar.damage = 8;
}
if (Input.GetButtonUp("Action2")){
HUDBar.isAttacking = false;
HUDBar.damage = 0;
}
}
// Apply gravity
if (Input.GetAxis("Action") && Power > 0 && !controller.isGrounded){
Power -= 1;
moveDirection = Vector3(0,0,Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed*2;
theCuton.animation.CrossFade("Jump");
trail.transform.position = transform.position;
trail.particleSystem.Play();
if (Input.GetAxis("Jump")){
moveDirection.y = jumpSpeed*2;
}
}
else {
moveDirection.y -= gravity * Time.deltaTime;
trail.particleSystem.Stop();
}
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
//correct slope bouncing
//rotate the controller
transform.Rotate(Vector3.up*Input.GetAxis("Horizontal")*speed/4);
}
The Problem: The character controller bounces down slopes instead of casually walking down them!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613122202im_/https://answers.unity.com/themes/thub/images/avi.jpg)