What is wrong here?
I am trying to make a script to move a ball(the main character) and he moves to right and left without problems or errors, but dont jump. Here is the code:
using UnityEngine;
using System.Collections;
public class MovementScript: MonoBehaviour {
//Variables
public GameObject player;
public Rigidbody2D rb2d;
public float velocity= 1;
public float jumpForce= 3;
// Use this for initialization
void Start () {
rb2d = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
}
void FixedUpdate(){
Movement();
}
//Movement
void Movement(){
//Jump
if(Input.GetKey("space")){
rb2d.AddForce(Vector2.up * jumpForce);
}
//Move to left
if(Input.GetKey("a")){
rb2d.AddForce(Vector2.left * velocity);
}
//Move to right
if(Input.GetKey("d")){
rb2d.AddForce(Vector2.right * velocity);
}
}
}
If you're jumping, don't you want to add the force pointing up ins$$anonymous$$d of down?
i would say that is most definitely the problem
Sorry, but that's not the error because I've tried with Vector2.up and then tried to Vector2.down, and none of the both worked.
No, the jumpForce in the inspector is 2.
Answer by robin-theilade · Sep 12, 2015 at 09:27 AM
You need to increase the jump force by factor 10 or more. Try setting it to 30. Your script works on my machine when the force is that great.
Answer by RoCkHeArTeD · Sep 12, 2015 at 05:57 PM
@mega_rodrigo In your RigidBody component, is your Kinemetic option unchecked? I'm guessing that could be the problem if it is checked.
Your answer
![](https://koobas.hobune.stream/wayback/20220612033407im_/https://answers.unity.com/themes/thub/images/avi.jpg)