martes, 3 de septiembre de 2024

GDScript animar un Sprite3d; se arrastra el Sprite3D al script y se escribe a continuacion .play();

 extends AnimatedSprite3D



# Called when the node enters the scene tree for the first time.

func _ready() -> void:

$".".play()

pass # Replace with function body.



# Called every frame. 'delta' is the elapsed time since the previous frame.

func _process(delta: float) -> void:

pass

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.

GDScript rota un Label presionando tecla escape; y lo rota de nuevo al presionar otra vez;

 extends Label



# Called when the node enters the scene tree for the first time.

func _ready() -> void:

pass # Replace with function body.



# Called every frame. 'delta' is the elapsed time since the previous frame.

func _process(delta: float) -> void:

if Input.is_action_just_pressed("escapedesalir"):

rotation_degrees += 180



----------------------------------------------------------------------------------------------------------------------- Explicacion:  muy util para el inicio de un juego, para mostrar y quitar textos explicativos, seguro que se puede combinar con imagenes tambien.........

sábado, 31 de agosto de 2024

GDScript diversos movimientos para con mouse y su rueda y sus botones y para teclas del pc; muevo una camara a capricho;

 extends MeshInstance3D


var is_rotating = false

var is_rotating2 = false

var is_rotating3 = false

var is_rotating4 = false


var speed = 11  # Adjust the speed as needed

var delta = 0.009

var delta2 = 0.009

var delta3 = 0.009

var delta4 = 0.0002

var delta5 = 0.0002

var delta6 = 0.09

var delta7 = 0.09



func _input(event):

if event is InputEventMouseButton:

if event.pressed and event.button_index == 1:

is_rotating = true

else:

is_rotating = false


if event.pressed and event.button_index == 2:

is_rotating2 = true

else:

is_rotating2 = false


if event.pressed and event.button_index == 3:

is_rotating3 = true

else:

is_rotating3 = false


if event.button_index == 3 and not event.pressed:

is_rotating4 = true

else:

is_rotating4 = false

if event.pressed and event.is_action("mouse_rueda_arriba"):

rotate_x(-0.04)

translate(Vector3( 0, -speed * delta6,0))  # Move forward

#translate(Vector3(0, 0, speed * delta))  # Move forward

if event.pressed and event.is_action("mouse_rueda_avajo"):

rotate_x(0.04)

translate(Vector3( 0, speed * delta7,0))  # Move forward

#translate(Vector3( 0, 0,-speed * delta))  # Move forward


if event is InputEventKey:

#if event.pressed and event.scancode == KEY_P:

if event.pressed and event.is_action("GRUADIRECCIONDERECHA-I-"):

translate(Vector3(-speed * delta, 0, 0))  # Move forward


if event.pressed and event.is_action("GRUADIRECCIONIZQUIERDA-U-"):

translate(Vector3(speed * delta2, 0, 0))  # Move forward

if event.pressed and event.is_action("GRUADIRECCIONALANTE-J-"):

translate(Vector3( 0, 0, speed * delta))  # Move forward


if event.pressed and event.is_action("GRUADIRECCIONATRAS-K-"):

translate(Vector3( 0, 0, -speed * delta))  # Move forward

if event.pressed and event.is_action("GRUADIRECCIONARRIBA-O-"):

translate(Vector3( 0, speed * delta5,0))  # Move forward

if event.pressed and event.is_action("GRUADIRECCIONABAJO-P-"):

translate(Vector3( 0, -speed * delta5,0))  # Move forward

if event.pressed and event.is_action("OOPARAINCLINACIONIZQUIERDA"):

rotate_z(0.04)


if event.pressed and event.is_action("PPPARAINCLINACIONDERECHA"):

rotate_z(-0.04)




func _process(delta: float) -> void:

if is_rotating:

rotate_y(0.009)


if is_rotating2:

rotate_y(-0.009)


if is_rotating3:

rotate_x(-0.0009)


if is_rotating4:

rotate_x(0.0009)


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

EXPLICACION:  

MOVER NIÑO -"W"-"A"-"S"-"D" --- "BOTON DEL RATON IZQUIERDO"-¡¡NIÑO MUERDE!!  Y GIRA IZQUIERDA CAMARA ,"BOTON DERECHO"¡¡NIÑO MUERDE!!  Y  GIRA DERECHA CAMARA ,


"RUEDA DEL RATON"  HACERCA ALEJA CAMARA.

 MOVER LA CAMARA -"U"-"I"-"J"-"K"-

 INCLINACION DE CAMARA-"O"-"P"



El script hace todos estos movimientos para mover un MeshInstance3D que contiene una camara, excepto los del texto de color azul que funcionan en otro script que mueve un CharacterBody3D este mueve al player y el player contiene el MeshInstance3D que contiene una camara,

CharacterBody3D es el padre y este un hijo el MeshInstance3D que contiene una camara,

viernes, 30 de agosto de 2024

GDScript activa una animacion con boton izquierdo del raton y tambien con el derecho;

 extends Node3D


var animacion_actual = "Default simplifiedAction"


func _ready() -> void:

# Reproduce la animación principal en bucle

$AnimationPlayer.play("Default simplifiedAction", -1)


func _input(event):

if event is InputEventMouseButton:

if event.pressed and event.button_index == 1:

# Pausa la animación principal y encola la secundaria

$AnimationPlayer.stop()

$AnimationPlayer.play("Default simplified|INFLACABEZA")


elif event.button_index == 1 and not event.pressed:

# Reanuda la animación principal

$AnimationPlayer.play("Default simplifiedAction", -1)






if event.pressed and event.button_index == 2:

# Pausa la animación principal y encola la secundaria

$AnimationPlayer.stop()

$AnimationPlayer.play("Default simplified|INFLACABEZA")


elif event.button_index == 1 and not event.pressed:

# Reanuda la animación principal

$AnimationPlayer.play("Default simplifiedAction", -1)

GDScript dispara y ataca tanto con boton izquierdo del raton como con el derecho;

 extends Area3D


var Bullet = preload("res://PERSONAJES/CAVEZA NIÑO MONSTRUO ATACANDO/caveza_ataca.tscn")

# Called when the node enters the scene tree for the first time.

func _ready() -> void:

pass # Replace with function body.



# Called every frame. 'delta' is the elapsed time since the previous frame.

func _process(delta: float) -> void:

pass




func _input(event):


if event is InputEventMouseButton:




if event.button_index == 1 and event.pressed :


var bullet = Bullet.instantiate()



add_child(bullet)




if event is InputEventMouseButton:




if event.button_index == 2 and event.pressed :


var bullet = Bullet.instantiate()



add_child(bullet)

miércoles, 28 de agosto de 2024

GDScript, movimientos y giros por mouse y teclado, presion de teclas de botones del mouse y de rotacion de su rueda;

 extends MeshInstance3D


var is_rotating = false

var is_rotating2 = false

var is_rotating3 = false

var is_rotating4 = false


var speed = 11  # Adjust the speed as needed

var delta = 0.009

var delta2 = 0.009

var delta3 = 0.009

var delta4 = 0.0002

var delta5 = 0.0002

var delta6 = 0.19

var delta7 = 0.19



func _input(event):

if event is InputEventMouseButton:

if event.pressed and event.button_index == 1:

is_rotating = true

else:

is_rotating = false


if event.pressed and event.button_index == 2:

is_rotating2 = true

else:

is_rotating2 = false


if event.pressed and event.button_index == 3:

is_rotating3 = true

else:

is_rotating3 = false


if event.button_index == 3 and not event.pressed:

is_rotating4 = true

else:

is_rotating4 = false

if event.pressed and event.is_action("mouse_rueda_arriba"):

translate(Vector3( 0, -speed * delta6,0))  # Move forward

if event.pressed and event.is_action("mouse_rueda_avajo"):

translate(Vector3( 0, speed * delta7,0))  # Move forward


if event is InputEventKey:

#if event.pressed and event.scancode == KEY_P:

if event.pressed and event.is_action("GRUADIRECCIONDERECHA-I-"):

translate(Vector3(-speed * delta, 0, 0))  # Move forward


if event.pressed and event.is_action("GRUADIRECCIONIZQUIERDA-U-"):

translate(Vector3(speed * delta2, 0, 0))  # Move forward

if event.pressed and event.is_action("GRUADIRECCIONALANTE-J-"):

translate(Vector3( 0, 0, speed * delta))  # Move forward


if event.pressed and event.is_action("GRUADIRECCIONATRAS-K-"):

translate(Vector3( 0, 0, -speed * delta))  # Move forward

if event.pressed and event.is_action("GRUADIRECCIONARRIBA-O-"):

translate(Vector3( 0, speed * delta5,0))  # Move forward

if event.pressed and event.is_action("GRUADIRECCIONABAJO-P-"):

translate(Vector3( 0, -speed * delta5,0))  # Move forward



func _process(delta: float) -> void:

if is_rotating:

rotate_y(0.0009)


if is_rotating2:

rotate_y(-0.0009)


if is_rotating3:

rotate_x(-0.0009)


if is_rotating4:

rotate_x(0.0009)