Hi world of Unity! I’m using this forum to constantly ask for help due to me being fairly new to the world of python Coding, where I was originally used to block coding.
Long story short, Trying to Build a game, following a tutorial on 3d platformer, and the following image is what i got for the jumping script.
The capsule is constantly Jumping, and I’m not even holding space. Moving is absolutely normal though, help would be appreciated!
-Papaya-man, or… it would be if my Username updated.
btw i’m using unity 2019 due to me mainly using unity in the past for VRChat related content.
Hi, i am new to this stuff too so pls dont mind if its not helpful. I try anyways:
First of all put a Debug.Log(“Player jumps”) unter your if (impt.GetButtonDown…) to see if it really triggers. i dont think so. its propably another part of your script that makes the play move + on y and than gravtiy applies.
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class JumpTest : MonoBehaviour
{
CharacterController controller;
public Vector3 jumpdir;
float jumpForce = 8f;
float moveSpeed = 3f;
void Start()
{
controller = GetComponent();
jumpdir = Vector3.zero;
}
void Update()
{
PlayerMovement();
}
void PlayerMovement()
{
float horizontalInput = Input.GetAxis(“Horizontal”);
float verticalInput = Input.GetAxis(“Vertical”);
Vector3 inputDir = new Vector3(horizontalInput, 0f, verticalInput);
// just to have a base to add the movement / Movement is 0 now
Vector3 move = Vector3.zero;
if (controller.isGrounded)
{ // or GetButtonDown…
if (Input.GetKeyDown(KeyCode.Space))
{
jumpdir.y = jumpForce;
}
}
// move (o movement) + input vert and hori + jumpDir + movespeed …
move = inputDir + jumpdir * (moveSpeed * Time.deltaTime);
// add gravity…
jumpdir.y += Physics.gravity.y * Time.deltaTime;
controller.Move(move);
}
}
in this example moveDir and jumpDir will be added together to move. Means you can move in the air/while jumping. if you dont want it this way just split those with if-statement or make a raycast to detect groundlayer. hope that helps