- Home /
Player wont jump (visual script),2d player does not jump (visual script)
I added in visual script: on button input (Jump) -- Add force (0/10) Now, I can see that when i press the space bar the graph lights up blue for a second. Yet, my player wont move a single bit. Help please :(
Answer by SoulBlaze06 · Jun 10, 2021 at 04:53 PM
I dont know about visual scripting but i can help you with c#. Dont worry you just have to add the player prefab to the script in the inspector and you are good to go...Make sure that the script name is exactly same as the class name and in your case it is JumpThePlayer
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
class JumpThePlayer : MonoBehaviour
{
Rigidbody2D player; // Drag the player Object to it in the inspector
public float JumpDistance = 10f; // How much high player can jump
public float JumpSpeed = 2f; //The Speed at which player will jump
void Start()
{
player = GetComponent<Rigidbody2D>();
}
void Update()
{
Jump();
}
private void Jump()
{
player.AddForce(0f , JumpDistance *JumpSpeed * Time.deltaTime);
}
}
I already solved the problem! I didn't do anything wrong with the script, I just accidently set the mass of the player to 90000 :'D but still thanks for your help, thats verry kind becouse i don't know anything about C#. I will definately use this script :) <3