lunes, 29 de enero de 2024

instancia muy simple en godot4.2;

 extends Area3D

var Bullet = preload("res://cubo.tscn")


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

func _ready():

pass # Replace with function body.



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

func _process(delta):


var bullet = Bullet.instantiate()

add_child(bullet)

pass



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

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

extends Area3D

var Bullet = preload("res://cubo.tscn")

func _ready():

pass # Replace with function body.

func _process(delta):

var bullet = Bullet.instantiate()

add_child(bullet)

pass


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

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

otra manera que funciona de instanciar en godot4.2

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

extends Area3D


var Bullet = preload("res://cubo.tscn")


var time = 0

var interval = 1.0  # Time interval between bullet instantiation


func _ready():

pass # Replace with function body.


func _process(delta):

time += delta


if time > interval:

time = 0


var bullet = Bullet.instantiate()

add_child(bullet)

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

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

este de debajo me falla pero creo que es por mi configuracion personalizada de teclas en godot algo que e de solucionar

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

extends Area3D


var Bullet = preload("res://cubo.tscn")


var pressed = false


func _ready():

pass # Replace with function body.


func _input(event):

if event is InputEventKey:

if event.scancode == KEY_SPACE:

if not pressed:

pressed = true

var bullet = Bullet.instantiate()

add_child(bullet)

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

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

otro ejemplo, con el boton izquierdo del raton me funciona por que lo e configurado desde un principio asignandole esa bariacion de entradas de teclado desde Proyecto---configuracion de proyecto-----

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

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

extends Area3D


var Bullet = preload("res://cubo.tscn")


func _ready():

pass # Replace with function body.


func _input(event):

if event is InputEventMouseButton:

if event.button_index == 1:

var bullet = Bullet.instantiate()

add_child(bullet)

------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
otro ejemplo al tocar un trigger
------------------------------------------------------------------------------------------------------


extends Area3D


var Bullet = preload("res://cubo.tscn")


func _ready():

    pass # Replace with function body.


func _physics_process(delta):

    # Check if the player is touching the trigger

    if $Trigger.is_colliding():

        var bullet = Bullet.instantiate()

        add_child(bullet)


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

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

este script que funciona solo aplica una fuerza para lanzar un cubo 

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


extends RigidBody3D



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

func _ready():

pass # Replace with function body.



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

func _process(delta):

pass

translate(Vector3(111,0,0) * get_process_delta_time())








No hay comentarios:

Publicar un comentario