Hey Guys, Im attempting to create my own custom controller with a rigidbody component and i came across a problem. i’ve already got the player jumping and looking around but i have trouble with making the player move with the horizontal and vertical keys.
Heres the code
#pragma strict
//Private Varibles (DO NOT REMOVE)
private var CanJump = false;
private var CanRun = false;
private var CanSlide = false;
//General Varibles
var WalkSpeed = 3.9f;
var RunSpeed = 3.0f;
var JumpHight = 4.0f;
var SlideSpeed = 4.0f;
var SlidingTime = 1.4f;
//Sound Varibles
var Footstep1 : AudioClip;
var Footstep2 : AudioClip;
var Collide : AudioClip;
var Slide : AudioClip;
var GrabOn : AudioClip;
var Ladder : AudioClip;
var HitSound : AudioClip;
var BreathingSound : AudioClip;
//animation Varibles
var CamAnim : Animation;
function Update () {
if(Input.GetKeyDown(KeyCode.Space)){
Jump();
}
}
function OnCollisionEnter(collision : Collision) {
if(collision.relativeVelocity.magnitude > 1){
CamAnim.Play("Jump_Grounded");
CanJump = true;
audio.PlayOneShot(Collide);
}
}
function OnCollisionExit(collision : Collision) {
CanJump = false;
}
function Jump () {
if(CanJump == true){
CamAnim.Play("Jump_Up");
rigidbody.velocity.y += JumpHight;
}
}
i tried AddForce but the player moves extremely slow and dose not respond to where i look.
i tried velocity but the player moves very fast and only one direction.
How can i make it move left, right, up, down. with the keys horizontal and vertical.
no i do not want to get the one from the unify wiki. i need to create my own custom controller, i tried ripping some parts of other codes but it still won’t work.
Can Some one help me out.