Mostrando entradas con la etiqueta extends CharacterBody3D script GDScript para mover personaje 3d con Godot4.3;. Mostrar todas las entradas
Mostrando entradas con la etiqueta extends CharacterBody3D script GDScript para mover personaje 3d con Godot4.3;. Mostrar todas las entradas

domingo, 1 de septiembre de 2024

extends CharacterBody3D script GDScript para mover personaje 3d con Godot4.3;

 extends CharacterBody3D


var rotate_speed = 10.1  # Rotation speed




const SPEED = 0.2  # Movement speed




const JUMP_VELOCITY = 3.5  # Jump velocity


var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")


func _ready():


# Replace with function body

pass


func _physics_process(delta):

translate(Vector3(0,0,-0.005))# PARA UNA CONSTANCIA DE MOVIMIENTO CONTINUO

if not is_on_floor():

velocity.y -= gravity * delta  # Apply gravity


if Input.is_action_just_pressed("ui_accept") and is_on_floor():

velocity.y = JUMP_VELOCITY  # Jump


#var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")  # Get input direction

var input_dir = Input.get_vector("ui_left", "ui_right", "andaradelante", "detenerse")  #ESTE FUNCIONABA ESTE FUNCIONABA





var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()


if direction:

velocity.x = direction.x * SPEED  # Move in X direction

velocity.z = direction.z * SPEED  # Move in Z direction


else:

velocity.x = move_toward(velocity.x, 0, SPEED)  # Stop horizontal movement

velocity.z = move_toward(velocity.z, 0, SPEED)  # Stop vertical movement


move_and_slide()  # Apply movement and collisions


var movimiento_vector = Vector3.ZERO  # Initialize movement vector



if Input.is_action_pressed("move_left"):

rotate_y(0.05)  # Rotate on Z axis (positive for left)

if Input.is_action_pressed("move_right"):

rotate_y(-0.05)  # Rotate on Z axis (negative for right)

#translate(Vector3(0.05,0,0))

if Input.is_action_pressed("detenerse"):

translate(Vector3(0.0,0.00,0.005))

rotate_y(-0.00)

if Input.is_action_pressed("andaradelante"):

translate(Vector3(0.0,0.00,-0.005))

rotate_y(-0.00)




------------------------------------------------------------------------------------------------------------------

Explicacion:  adelante hacia atras giro sobre simismo izquierda y derecha y salta.