extends Area3D
var Calva = preload("res://calva.tscn")
func _ready():
pass # Replace with function body.
func _on_area_entered(area):
var calva = Calva.instantiate()
add_child(calva)
pass # Replace with function body.
Godot, scripts para Godot estudios y aprendizajes, Creacion de videojuegos. Creacion y publicacion de videojuegos en internet. Como hacer videojuegos. C# unity. Animaciones unity blender. Personajes videojuegos graficos dibujos. Diseño grafico. Comic. Animaciones gif. Dibujo de retratos. Realidad virtual. Cine y realidad virtual.
extends Area3D
var Calva = preload("res://calva.tscn")
func _ready():
pass # Replace with function body.
func _on_area_entered(area):
var calva = Calva.instantiate()
add_child(calva)
pass # Replace with function body.
y ahora que empiezo a comprender el tema de instanciar objetos en las escenas con Godot4.2, me boy a poner las botas haciendo virgerias con este estupendo motor de juegos gratuito........Godot.
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)
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())
extends CharacterBody3D
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
const FRICTION = 25
const HORIZONTAL_ACCELERATION = 30
const MAX_SPEED=5
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@onready var camera = $Camera3D
func _ready():
Input.mouse_mode=Input.MOUSE_MODE_CAPTURED
func _unhandled_input(event):
if event is InputEventMouseMotion and Input.mouse_mode==Input.MOUSE_MODE_CAPTURED:
rotate_y(-event.relative.x * .005)
camera.rotate_x(-event.relative.y * .005)
camera.rotation.x = clamp(camera.rotation.x, -PI/2, PI/2)
func _unhandled_key_input(event):
if Input.is_action_just_pressed("ui_cancel"):
if Input.mouse_mode==Input.MOUSE_MODE_CAPTURED:
Input.mouse_mode=Input.MOUSE_MODE_VISIBLE
else:
Input.mouse_mode=Input.MOUSE_MODE_CAPTURED
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
# Handle Jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor() and Input.mouse_mode==Input.MOUSE_MODE_CAPTURED:
velocity.y += JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Vector3.ZERO
var movetoward = Vector3.ZERO
input_dir.x = Input.get_vector("move_left", "move_right", "move_forward", "move_backward").x
input_dir.y = Input.get_vector("move_left", "move_right", "move_forward", "move_backward").y
input_dir=input_dir.normalized()
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
direction *= SPEED
velocity.x = move_toward(velocity.x,direction.x, HORIZONTAL_ACCELERATION * delta)
velocity.z = move_toward(velocity.z,direction.z, HORIZONTAL_ACCELERATION * delta)
var angle=5
#rotation_degrees=Vector3(input_dir.normalized().y*angle,rotation_degrees.y,-input_dir.normalized().x*angle)
var t = delta * 6
if Input.mouse_mode==Input.MOUSE_MODE_CAPTURED:
rotation_degrees=rotation_degrees.lerp(Vector3(input_dir.normalized().y*angle,rotation_degrees.y,-input_dir.normalized().x*angle),t)
move_and_slide()
force_update_transform()
extends RigidBody
var velocity = Vector3()
func _physics_process(delta):
# Obtener la velocidad actual del RigidBody
velocity = get_linear_velocity()
# Ajustar la velocidad según las teclas presionadas
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_up"):
velocity.y += 1
if Input.is_action_pressed("ui_down"):
velocity.y -= 1
# Aplicar la nueva velocidad al RigidBody
set_linear_velocity(velocity)
-----------------------------------------------------------------------
otra forma
---------------------------------------------------------------------------------
extends RigidBody
var velocity = Vector2()
func _physics_process(delta):
# Obtener la velocidad actual del RigidBody
velocity = get_linear_velocity()
# Ajustar la velocidad según las teclas presionadas
if Input.is_action_pressed("ui_left"):
velocity.x -= 10 * delta
if Input.is_action_pressed("ui_right"):
velocity.x += 10 * delta
if Input.is_action_pressed("ui_up"):
velocity.y += 10 * delta
if Input.is_action_pressed("ui_down"):
velocity.y -= 10 * delta
# Aplicar la nueva velocidad al RigidBody
set_linear_velocity(velocity)
extends Spatial
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
#func _ready():
#var Projectile = load("res://Projectile.tscn")
#var ProjCopies = Projectile.instance()
#add_child(ProjCopies)
#pass # Replace with function body.
#func _process(delta):
#pass
func spawn_ProjCopies():
var Projectile = load("res://Projectile.tscn")
var ProjCopies = Projectile.instance()
add_child(ProjCopies)
func _on_Timer_timeout():
spawn_ProjCopies()
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
EXPLICACION : SI QUIERES INSTANCIAR OBJETOS DENTRO DE UNA ESCENA USA LA VERSION 3 DE GODOT DONDE TIENE EL NODO SPATIAL LA VERSION 4.2 LLEVO SEMANAS INTENTANDOLO Y NO ENCUENTRO NI EJEMPLOS POR INTERNET....
aqui facilito un video del tema es una practica que hice de otro que vi en internet y con paciencia logre el mismo resultado.........mi fallo usaba la version de godot4,2 y este video solo funciona si se usa godot3 en la version 3 recalco version 3.5.3 estable
extends Spatial
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
#func _ready():
#var Projectile = load("res://Projectile.tscn")
#var ProjCopies = Projectile.instance()
#add_child(ProjCopies)
#pass # Replace with function body.
#func _process(delta):
#pass
func spawn_ProjCopies():
var Projectile = load("res://Projectile.tscn")
var ProjCopies = Projectile.instance()
add_child(ProjCopies)
#func _on_Timer_timeout():
#spawn_ProjCopies()
func _input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT:
spawn_ProjCopies()
-----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
EXPLICACION: AQUI FUNCIONA PRESIONANDO BOTON IZQUIERDO DEL MOUSE
----------------------------------------------------------------------------------------------------------------
extends Spatial
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
#func _ready():
#var Projectile = load("res://Projectile.tscn")
#var ProjCopies = Projectile.instance()
#add_child(ProjCopies)
#pass # Replace with function body.
#func _process(delta):
#pass
func spawn_ProjCopies():
var Projectile = load("res://Projectile.tscn")
var ProjCopies = Projectile.instance()
add_child(ProjCopies)
#func _on_Timer_timeout():
#spawn_ProjCopies()
func _input(event):
if event is InputEventKey:
if event.scancode == KEY_A:
spawn_ProjCopies()
-----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
EXPLICACION: AQUI FUNCIONA PRESIONANDO LETRA "A" DEL TECLADO
----------------------------------------------------------------------------------------------------------------
extends Area3D
# 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
func _on_area_entered(area):
var parent = get_parent()
var Area3DBETA = parent.get_node("Area3DBETA")
#Area3DBETA.queue_free()
get_node("CollisionShape3DBETA").queue_free()
get_node("AMETRALLADOR DE BLENDER PINTADOBETA").queue_free()
get_node ("MeshInstance3DBETA")
scale.y+=5.0
scale.x+=5.2
scale.z+=5.2
pass # Replace with function body.
func _on_area_exited(area):
$AudioStreamPlayer.play()
pass # Replace with function body.
extends Area3D
# 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
func _on_area_exited(area):
queue_free()
pass # Replace with function body.
func _on_area_entered(area):
$"../../AudioStreamPlayer".play()
pass # Replace with function body.
$"../../AudioStreamPlayer".play()
pass # Replace with function body.
emite sonido.........
func _on_area_exited(area):
queue_free()
pass # Replace with function body.
se borra su contenido.
extends Area3D
# 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
func _on_area_entered(area):
var parent = get_parent()
var Area3DBETA = parent.get_node("Area3DBETA")
#Area3DBETA.queue_free()
get_node("CollisionShape3DBETA").queue_free()
get_node("AMETRALLADOR DE BLENDER PINTADOBETA").queue_free()
get_node ("MeshInstance3DBETA")
scale.y+=2.2
scale.x+=2.2
scale.z+=2.2
pass # Replace with function body.
extends Area3D
# 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
func _on_area_entered(area):
var parent = get_parent()
var Area3DBETA = parent.get_node("Area3DBETA")
#Area3DBETA.queue_free()
get_node("CollisionShape3DBETA").queue_free()
get_node("AMETRALLADOR DE BLENDER PINTADOBETA").queue_free()
pass # Replace with function body.
-----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------
EXPLICACION: DE LINEAS FUNDAMENTALES.....
func _on_area_entered(area):-------------Area donde entra un objeto un proyectil por ejemplo.
var parent = get_parent()-------------------Parentesco.
var Area3DBETA = parent.get_node("Area3DBETA")------Nombre del padre desde donde salen los hijos a borrar al haber una colision.
#Area3DBETA.queue_free()---------------------No hace nada al haber este signo "#" si no lo tuviese borraria el Area3DBETA padre completa hijos incluidos
WorldEnvironment, la clave es poner este nodo de padre de todo el juego principal, como escena principal, a partir de hay es muy intuitivo cambiar el color de la ambientacion, en el video muestro los pasos principales, a partir de hay ,,,,,,,,,,,,,,,,,,,¡¡¡¡¡¡¡¡¡¡¡
Crei en un principio que DirectionalLight3D era el que hacia la luz del cielo pero no es, .........es WorldEnvironment y a de estar como raiz de todo, lo que si hace DirectionalLight3D es si se activa Shadow son las sombras que las crea Godot, yo al aparato volar le puesto una luz linterna que queda muy bien con esa ambientacion oscura que me gusta dar a casi todos mis juegos...
EN CONSTRUCCION LA DESCARGA DEL JUEGO POR PROBLEMAS TECNICOS DE CONEXION INTERNET..........................................................................................................................................................................................................................................................17-1-24.......ESTOY EN ELLO----------
extends RigidBody3D
func _ready():
# Agrega el código que deseas ejecutar aquí.
pass
func _process(delta):
# Agrega el código que deseas ejecutar aquí.
pass
#func _input(event: InputEvent):
#if event is InputEventKey and event.scancode == KEY_N and event.pressed:
#rotate_y(0.1)
func _unhandled_input(event):
#if event is InputEventKey:
#if event.pressed and event.keycode == KEY_O:
if event is InputEventKey and event.pressed:
if event.keycode == KEY_J:
#queue_free()
translate(Vector3(111,0,0) * get_process_delta_time())
$AudioStreamPlayer.play()
pass
if event is InputEventKey and event.pressed:
if event.keycode == KEY_L:
#queue_free()
translate(Vector3(-111,0,0) * get_process_delta_time())
$AudioStreamPlayer.play()
pass
if event is InputEventKey and event.pressed:
if event.keycode == KEY_I:
translate(Vector3(0,0,111) * get_process_delta_time())
$AudioStreamPlayer.play()
pass
if event is InputEventKey and event.pressed:
if event.keycode == KEY_K:
#queue_free()
translate(Vector3(0,0,-111) * get_process_delta_time())
$AudioStreamPlayer.play()
pass
if event is InputEventKey and event.pressed:
if event.keycode == KEY_Z:
#queue_free()
translate(Vector3(0,111,0) * get_process_delta_time())
pass
if event is InputEventKey and event.pressed:
if event.keycode == KEY_R:
#queue_free()
translate(Vector3(0,-111,0) * get_process_delta_time())
pass
#if event is InputEventKey and event.pressed:
#if event.keycode == KEY_O:
#queue_free()
#rotate_y(0.5)
#pass
#if event is InputEventKey and event.pressed:
#if event.keycode == KEY_P:
#queue_free()
#rotate_y(-0.5)
#pass
#if event.keycode == KEY_9:
#add_constant_force(Vector3(0,-33,0))
#pass
#if event.keycode == KEY_8:
#add_constant_force(Vector3(0,33,0))
#pass
if event.keycode == KEY_Z:
apply_torque_impulse(Vector3(0,-0.1,0))
pass
if event.keycode == KEY_X:
apply_torque_impulse(Vector3(0, 0.1,0))
pass
if event.keycode == KEY_E:
apply_impulse(Vector3(0,110,0))
pass
if event.keycode == KEY_W:
#move_and_slide(Vector3(0, 0, 40))
apply_impulse(Vector3(0,0,40))
pass
if event.keycode == KEY_S:
apply_impulse(Vector3(0,0,-40))
pass
if event.keycode == KEY_A:
apply_impulse(Vector3(40,0,0))
pass
if event.keycode == KEY_D:
apply_impulse(Vector3(-40,0,0))
pass
if event.keycode == KEY_1:
rotate_z(1)
pass
if event.keycode == KEY_2:
rotate_x(1)
#queue_free()
pass
---------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------
EXPLICACION: FUNCIONA ELEVARSE -E- ALANTE ATRAS IZQUIERDA DERECHA W-A-S-D
GIRAR -Z-X- , TIENE EL DEFECTO QUE CUANDO A GIRADO AL PRESIONAR -W- YA NO AVANZA ADELANTE AVANZA HACIA ATRAS, Y AL GIRAR DE NUEVO , VUELVE A AVANZAR PRESIONANDO -W-, CON LA -S- OCURRE IGUAL VA HACIA ATRAS Y SI AGIRADO CAMBIA Y VA HACIA ADELANTE........YA LO CORREGIRE POCO A POCO....
extends MeshInstance3D
# 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
func _unhandled_input(event):
if event is InputEventKey:
if event.pressed and event.keycode == KEY_M:
get_tree().reload_current_scene()
#rotate_y(90.88)
-------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
Explicacion;
Script para godot3d 4.2 cuando presiono tecla "M" se reinicia el juego; esta puesto en un MeshInstance3D; y es bicnieto; me vengo a referir , intento aclarar el nodo raiz padre del juego es un
World de el sale un Area3d de esta sale un CollisionShape3D de este asi mismo sale el MeshInstance3D contenedor del script que funciona perfectamente, ejecuto el juego y cuando presiono tecla "m" se empieza el juego de nuevo.
extends Area3D
# 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
func _on_area_entered(area):
var parent = get_parent()
var Turbo = parent.get_node("Turbo")
var Turbo2 = parent.get_node("Turbo2")
var CollisionShape3DCARROCERIA = parent.get_node("CollisionShape3DCARROCERIA")
var ModeloElicopteroobj = parent.get_node("ModeloElicopteroobj")
Turbo.queue_free()
Turbo2.queue_free()
CollisionShape3DCARROCERIA.queue_free()
ModeloElicopteroobj.queue_free()
get_node("CollisionShape3D mas amarillo aun").queue_free()
get_node("MeshInstance3D SUPERAMARILLO").queue_free()
pass # Replace with function body.
extends Area3D
# 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
func _on_area_entered(area):
var parent = get_parent()
var Turbo = parent.get_node("Turbo")
Turbo.queue_free()
get_node("CollisionShape3D mas amarillo aun").queue_free()
get_node("MeshInstance3D SUPERAMARILLO").queue_free()
pass # Replace with function body.
EXPLICACION:
El script se pone en el Area 3d donde estan los elementos que borraremos cuando algo entre en dicha area3d contenedora tambien del script, esta parte son hermanos:
var parent = get_parent()
var Turbo = parent.get_node("Turbo")
Turbo.queue_free()
esta otra parte son hijos:
get_node("CollisionShape3D mas amarillo aun").queue_free()
get_node("MeshInstance3D SUPERAMARILLO").queue_free()
pass # Replace with function body.
extends Area3D
# 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
func _on_area_entered(area):
get_node("SOLDADOTIESO2VIVO").queue_free()
get_node("CollisionShape3D10 borroestoprueba").queue_free()
$AnimationPlayer.play("PELICULA180")
extends Area3D
# 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
func _on_area_entered(area):
get_node("SOLDADOTIESO2VIVO").queue_free()
$AnimationPlayer.play("PELICULA180")