- Home /
how can i make my character jump?
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.
None of these are working for me :/ Can someone post a full player jump script?
Unity Answers does not write or find scripts for you. We answer specific questions to help you write your own code. If you have a specific situation, post your code attempt and all the particulars as a new question.
Answer by Brodie Winning · Jan 19, 2011 at 06:48 AM
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.
Answer by anilo · Mar 29, 2013 at 08:35 PM
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 );
> }
>}
Dear anilo.. Your code allows jump only at the same place. Suppose if i want my character to jump and cover a certain length, how would it be possible. I only want to use the Jump button.
I used your code but Unity's compilers said this Assets/Scipts/PlayerController.cs(23,36): error CS1061: Type bool' does not contain a definition for
SetBool' and no extension method SetBool' of type
bool' could be found (are you missing a using directive or an assembly reference?)
Answer by DigitalCyan · Mar 20, 2016 at 09:33 AM
To lock the mouse just use Cursor.visible = false; in your void Start.
Simple as that :)
Answer by pr_0_0_ · May 25, 2020 at 09:23 AM
#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.
Just realised this question was asked 10 years ago. I'm so stupid.
I mean this kinda helps me out because i can get my character to jump but if i hold down the “w” key the character just stays in the air.
Answer by AliAzin · Oct 14, 2010 at 05:56 AM
Add "FPSWalker" script in standard assets to your character.
Your answer
Follow this Question
Related Questions
I need help with my script 3 Answers
FPS camera script - keeps reverting to 0,0,0 rotation 1 Answer
Camera Height-based crouch script 2 Answers
Camera Bobbing and Stairs 4 Answers
I want to change gun position with my camera joystick 0 Answers