what is the script for my character to jump? right now i have it with character conroller but its not jumping.... also if some1 can tell me how to lock the mose so you cant see it that be great.
Try transform.position += transform.up * jumpSpeed * Time.deltaTime;
That should do it but you need a variable called jumpSpeed and you need gravity on your player or he'll stay in the air.
Characters jump up and down along the y-axis.
So, all you ned to do is write a short script in your Update() method so that you can detect the button pressed and then translate that into a movement along the y-axis.
Here’s a snippet.
> function Update () {
> if (Input.GetKeyDown ("space")){
> transform.Translate(Vector3.up * 260 * Time.deltaTime, Space.World);
> }
>}
Another simple technique is to use an animation controller. Set the transition from walking animation to a jumping animation with a simple bool variable and then your character will play a different animation whenever you toggle the bool value.
Here’s a snippet.
> function Update () {
> if (Input.GetKeyDown ("space")){
> myAnimator.SetBool("letsJump", true );
> }
>}
#pragma strict
public var jumpHeight : int = 10;
var inAir : boolean = false;
function Update () {
if (Input.GetAxis ("Jump") && inAir == false) {
GetComponent.<Rigidbody>().velocity.y = jumpHeight;
inAir = true;
}
}
function OnCollisionEnter () {
inAir = false;
}
The inAir variable will ensure you don’t multi-jump.
To lock the mouse just use Cursor.visible = false; in your void Start.
Simple as that ![]()
Add "FPSWalker" script in standard assets to your character.