Ok Im making a project and I cant seem to make my character to go DOWN when i jump he either starts flying or gets stuck to ground. my script as is is:
var character: CharacterController;
var speed: float = 5.0; // moving speed
var direction: float = 1; // direction (-1 means -x)
var directionup: float = 2;
var directionback: float = -1;
var runanimation: AnimationClip;
var placeanimation: AnimationClip;
var attackanimation: AnimationClip;
var dieanimation: AnimationClip;
var idleanimation: AnimationClip;
var jumpanimation: AnimationClip;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
function Start(){
character = transform.GetComponent(CharacterController);
}
function Update(){
if(Input.GetKey("d")){
character.Move(Vector3.forward * speed * direction * Time.deltaTime);
animation.Play(runanimation.name);
}
if(Input.GetKey("a")){
character.Move(Vector3.forward * speed * directionback * Time.deltaTime);
animation.Play(runanimation.name);
}
if(Input.GetKey("w")){
character.Move(Vector3.right * speed * directionback * Time.deltaTime);
}
if(Input.GetKey("s")){
character.Move(Vector3.right * speed * direction * Time.deltaTime);
}
if(Input.GetMouseButton(1)){
animation.Play(placeanimation.name);
animation.Stop(idleanimation.name);
}
if(Input.GetKey("space")){
character.Move(Vector3.up * speed * direction * Time.deltaTime);
animation.Play(jumpanimation.name);
}
if (Mathf.Abs(Input.GetAxis("Vertical")) <= 0.1){
animation.CrossFade(idleanimation.name);
}
if(Input.GetMouseButton(0)){
animation.Play(attackanimation.name);
animation["attack"].layer = -1;
animation.Stop(idleanimation.name);
}
}
function LateUpdate(){
moveDirection.y -= gravity * Time.deltaTime;
character.Move(moveDirection * Time.deltaTime);
}
its urgent that i get some help soon Thank you everyone
@Tracey I'm not sure I understand what's going on, and hope that you can give a bit more specific information. You say 'when the character jumps' - I assume that refers to Input.GetKey("space")? You say the character either starts flying or gets stuck to the ground - can you explain a little more what you mean by 'flying' (does the character just continue to rise at a steady pace, or hover, or...), and 'stuck to the ground?' What about other components attached to the character? Any other scripts, rigidbody, character controllers, etc.?
– Julien-LyngeI give you -1 for using URGENT in your subject/title. NO question is more important than anyone elses in here. This forum is about great answers for common problems. If you are so important/urgent, hire on of us to solve it through the normal forum. Thanks.
– BerggreenDKDude I said urgent because this is for a college project that was due the next dday
– anon34150999