extends CharacterBody3D
var rotation_angle = 0.0 # Ángulo de rotación actual
var rotate_speed = 3.1 # Velocidad de rotación
const SPEED = 0.1 # Velocidad de movimiento
const JUMP_VELOCITY = 4.0 # Velocidad de salto
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
func _ready():
pass
func _physics_process(delta):
# Movimiento vertical (saltar)
if not is_on_floor():
velocity.y -= gravity * delta
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Movimiento horizontal (basado en input)
var input_dir = Input.get_vector("ui_left", "ui_right", "andaradelante", "detenerse")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
# Rotación (limitada a 60 grados)
if Input.is_action_pressed("move_left"):
if rotation_angle > -PI / 3: # -60 grados en radianes
rotation_angle -= rotate_speed * delta
rotate_y(rotate_speed * delta)
if Input.is_action_pressed("move_right"):
if rotation_angle < PI / 3: # 60 grados en radianes
rotation_angle += rotate_speed * delta
rotate_y(-rotate_speed * delta)
# Detener movimiento (opcional)
if Input.is_action_pressed("detenerse"):
velocity.x = 0
velocity.z = 0
rotate_y(0) # Opcional, para detener la rotación también
# Movimiento continuo (opcional)
# Puedes reemplazar estas líneas con el movimiento deseado
# translate(Vector3(0, 0, -0.01)) # Movimiento continuo hacia adelante
-------------------------------------------------------------------------
NUEVA COMBINACION A 60 GRADOS CADA VEZ QUE SE PRESIONA TECLA
----------------------------------------------------------------------------------------------------
extends CharacterBody3D
var rotation_angle = 0.0 # Current rotation angle
var rotate_speed = 10.0 # Rotation speed (adjust as needed)
const SPEED = 0.2 # Movement speed
const JUMP_VELOCITY = 4.5 # Jump velocity
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
func _physics_process(delta):
# Vertical movement (jumping)
if not is_on_floor():
velocity.y -= gravity * delta
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Horizontal movement (based on input)
var input_dir = Input.get_vector("ui_left", "ui_right", "andaradelante", "detenerse")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
# Apply movement and rotation
move_and_slide()
# Rotation (limited to 60 degrees)
if Input.is_action_pressed("move_left"):
if rotation_angle > -PI / 3:
rotation_angle -= rotate_speed * delta
rotate_y(rotate_speed * delta)
elif Input.is_action_pressed("move_right"):
if rotation_angle < PI / 3:
rotation_angle += rotate_speed * delta
rotate_y(-rotate_speed * delta)
else:
rotation_angle = move_toward(rotation_angle, 0, rotate_speed * delta)
rotate_y(-rotation_angle * delta) # Smoothly rotate back to center
# Movement based on "andaradelante" action (optional)
if Input.is_action_pressed("andaradelante"):
translate(Vector3(0, 0, -0.009))
# Mouse-based movement (optional)
if Input.is_action_pressed("mouse_left"):
translate(Vector3(0.0, 0.00, -0.04))
--------------------------------------------------------------------------
OTRO RESULTADO DE EQUILIBRIO DE GIRO
---------------------------------------------------------------------------------
extends CharacterBody3D
var rotation_angle = 0.0 # Ángulo de rotación actual
var rotate_speed = 10.0 # Velocidad de rotación
const SPEED = 0.2 # Velocidad de movimiento
const JUMP_VELOCITY = 4.5 # Velocidad de salto
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
var is_rotating_left = false
var is_rotating_right = false
func _physics_process(delta):
# Vertical movement (jumping)
if not is_on_floor():
velocity.y -= gravity * delta
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Horizontal movement (based on input)
var input_dir = Input.get_vector("ui_left", "ui_right", "andaradelante", "detenerse")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
# Apply movement and rotation
move_and_slide()
# Rotation (limited to 60 degrees, one time per press)
if Input.is_action_just_pressed("move_left") and not is_rotating_left:
if rotation_angle > -PI / 3:
rotation_angle -= rotate_speed * delta
rotate_y(rotate_speed * delta)
is_rotating_left = true
elif Input.is_action_just_released("move_left"):
is_rotating_left = false
if Input.is_action_just_pressed("move_right") and not is_rotating_right:
if rotation_angle < PI / 3:
rotation_angle += rotate_speed * delta
rotate_y(-rotate_speed * delta)
is_rotating_right = true
elif Input.is_action_just_released("move_right"):
is_rotating_right = false
# Movement based on "andaradelante" (optional)
if Input.is_action_pressed("andaradelante"):
translate(Vector3(0, 0, -0.009))