Godot Version
Godot 4.6
Question
Hello, I’m working on a 3d platformer using tank controls and i cant get gravity to work at all. I have this currently, built of the default movement script.
extends CharacterBody3D
@export var move_speed: float = 6.0
@export var turn_speed: float = 3.0
@export var JUMP_VELOCITY = 45
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_released("ollie") and is_on_floor():
velocity.y = JUMP_VELOCITY
print(velocity)
var input_vector = Input.get_vector("turn_right", "turn_left", "move_down", "move_up")
# Rotate the body
rotate_y(input_vector.x * turn_speed * delta)
# Set velocity based on the local Z-axis (forward)
var speed = input_vector.y * move_speed
velocity = -global_transform.basis.z * speed
move_and_slide()
Any help would be great, thanks!