domingo, 10 de noviembre de 2024

Ejercicios de animar con Blender y pasar a Godot4.3;

 


Gira la camara3d y por tiempo la borra hace las dos cosas; GDScript para godot 4.3 en 3d;

 extends Camera3D


var target_rotation_x = PI / 2  # Ángulo de rotación objetivo en el eje X

var target_rotation_y = PI / 2  # Ángulo de rotación objetivo en el eje Y


var current_rotation_x = 0.0

var current_rotation_y = 0.0


var rotation_speed = 0.3  # Ajusta esta variable para cambiar la velocidad de rotación


var is_rotating_forward_x = true  # Indica si la rotación en X es en sentido horario

var is_rotating_forward_y = false  # Indica si la rotación en Y es en sentido horario



var tiempo_transcurrido = 0.0 





func _process(delta: float) -> void:


tiempo_transcurrido += delta


# Eliminar el nodo después de 2 segundos

if tiempo_transcurrido >= 8.28:

queue_free()



# Rotación en el eje X

if is_rotating_forward_x:

if current_rotation_x < target_rotation_x:

rotate_x(delta * rotation_speed)

current_rotation_x += delta * rotation_speed

if current_rotation_x >= target_rotation_x:

current_rotation_x = target_rotation_x

is_rotating_forward_x = false

else:

if current_rotation_x > -target_rotation_x:

rotate_x(-delta * rotation_speed)

current_rotation_x -= delta * rotation_speed

if current_rotation_x <= -target_rotation_x:

current_rotation_x = -target_rotation_x

is_rotating_forward_x = true


# Rotación en el eje Y

if is_rotating_forward_y:

if current_rotation_y < target_rotation_y:

rotate_y(delta * rotation_speed)

current_rotation_y += delta * rotation_speed

if current_rotation_y >= target_rotation_y:

current_rotation_y = target_rotation_y

is_rotating_forward_y = false

else:

if current_rotation_y > -target_rotation_y:

rotate_y(-delta * rotation_speed)

current_rotation_y -= delta * rotation_speed

if current_rotation_y <= -target_rotation_y:

current_rotation_y = -target_rotation_y

is_rotating_forward_y = true

Ejemplo de compensar retroceso de un CharacterBody3D cuando dispara; en GDScript para Godot 4.3;

 extends CharacterBody3D


var rotate_speed = 10.1  # Rotation speed




const SPEED = 0.2  # Movement speed




const JUMP_VELOCITY = 4.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

translate(Vector3(0,0,-0.00))# 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)


move_and_slide()


# Movimiento basado en el botón izquierdo del ratón (acción "mouse_left")

if Input.is_action_pressed("mouse_left"):

# Mover hacia adelante

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