![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | AjayDas |
I’m new to the Godot engine and I’m trying to make CharacterBody3D Jump. So wrote below code to have better control on gravity for the jump so that I can make player fall faster.
const SPEED = 5.0
@export var JUMP_HEIGHT = 3
@export var GRAVITY = 20
@export var JUMP_PEEK_TIME : float
@export var JUMP_DECEND_TIME : float
var Jump_Gravity = (2 * JUMP_HEIGHT) / (JUMP_PEEK_TIME * JUMP_PEEK_TIME)
var Fall_Gravity = (2 * JUMP_HEIGHT) / (JUMP_DECEND_TIME * JUMP_DECEND_TIME)
var Jump_Velocity = sqrt(2 * GRAVITY * JUMP_HEIGHT)
# Get the gravity from the project settings to be synced with RigidBody nodes.
func get_gravity():
if velocity.y > 0:
print("Jump Gravity:", Jump_Gravity)
#return Jump_Gravity
else:
print("Fall Gravity:", Fall_Gravity)
#return Fall_Gravity
return 10
I’m returning a constant value here just for debugging because it initially returned infinite value.
Output:
Jump Gravity:inf
Fall Gravity:inf
looks like both the variables were getting divided by 0, even though I have initialized non zero positive values in inspector (3.5 and 2.5 for jump and fall) .So I initialized the dividend values as 1
@export var JUMP_PEEK_TIME : float = 1
@export var JUMP_DECEND_TIME : float = 1
I got below output:
Output:
Jump Gravity: 6
Fall Gravity: 6
I’m not sure if I’m missing anything here or if godot is not taking inspector values for those variables.
Is there any way I can resolve this? Thanks in advance!