- Home /
Crouch Scale Problem!
Hi Guys, i pickup this script of Sprint + crouch but, when crouch the weapon crounch too! i not know what i make D: please help!
Script:
var walkSpeed: float = 7; // regular speed
var crchSpeed: float = 3; // crouching speed
var runSpeed: float = 20; // run speed
private var chMotor: CharacterMotor;
private var tr: Transform;
private var dist: float; // distance to ground
function Start(){
chMotor = GetComponent(CharacterMotor);
tr = transform;
var ch:CharacterController = GetComponent(CharacterController);
dist = ch.height/2; // calculate distance to ground
}
function Update(){
var vScale = 1.0;
var speed = walkSpeed;
if (Input.GetKey("left shift") || Input.GetKey("right shift")){
speed = runSpeed;
}
if (Input.GetKey("c")){ // press C to crouch
vScale = 0.5;
speed = crchSpeed; // slow down when crouching
}
chMotor.movement.maxForwardSpeed = speed; // set max speed
var ultScale = tr.localScale.y; // crouch/stand up smoothly
tr.localScale.y = Mathf.Lerp(tr.localScale.y, vScale, 5*Time.deltaTime);
tr.position.y += dist * (tr.localScale.y-ultScale); // fix vertical position
}
Preview of cfg:
Player> ( The Crouch Script are placed here )
Body
MainCamera>
GunCam>
//Weapons//
Scaling the player really isn't a good way to implement crouching behaviour. Try modifying the size of the collider component, ins$$anonymous$$d!
Your answer
Follow this Question
Related Questions
how to make a character lean over or back when looking up or down 2 Answers
aiming with animation 1 Answer
Equiping Weapon to a Character 1 Answer
Switching weapons animation with mecanim? 2 Answers
Animation system 1 Answer