Mostrando entradas con la etiqueta Video donde muestro y comento con mi voz en of lo mas importante aprendido con Godot asta la fecha; instanciar. Mostrar todas las entradas
Mostrando entradas con la etiqueta Video donde muestro y comento con mi voz en of lo mas importante aprendido con Godot asta la fecha; instanciar. Mostrar todas las entradas

viernes, 2 de febrero de 2024

Video donde muestro y comento con mi voz en of lo mas importante aprendido con Godot asta la fecha; instanciar, lod, memoria;

el video en godot 4.2 comentado con mi voz en of.




En el video muestro como se instancia un cubo que hace de proyectil, todo esta en la version de Godot 4.2, en la version 3.5 el tema de instanciar tiene diferencias por que parte del nodo Spatial ,que ya no existe en la version 4.2 , me volvia loco intentandolo en la version 4.2 y claro no podia por que hay diferencias, como que para empezar Spatial ya no se utiliza, tambien empiezo a mostrar intentos de gestionar la memoria con Godot, los proyectiles por ejemplo cuando dejo de presionar la tecla de disparar el proyectil se borra del juego y de la memoria, si no se hace algo que los borre, el juego se pararia porque no dejaria de dibujar los proyectiles y de consumir los recursos de la ram o la rom o de la memoria que use la targeta grafica,

Creo que con estos minimos conocimientos, ya se puede empezar a hacer algun juego divertido, porque al saber instanciar, puedes matar enemigos, cambiarles las animaciones ,al cambiar una copia del enemigo con una animacion diferente, crear explosiones, que salgan rayos de edificios destruidos, fuego de bidones , agua de depositos, humo de fuegos apagados, y al saber borrar objetos por colisiones de objetos que entran en su area3d mas de lo mismo....poco a poco ya me podre centrar mas en la parte artistica modelando y pintando mejores personajes, tambien e aprendido a hacer puertas animadas que se pueden mover por todo el escenario haciendo todas las copias que me vengan en gana....¡¡¡¡¡.viva Godot!!!!!





aqui en la version godot3.5 el video, no comento nada solo echo captura en video del estudio



otro video del tema en la version de godot 4.2 no comento nada solo es captura de video

video de encima ahorra memoria en godot, menos poligonos menos gasto de recursos de tu maquina mas fluidez y es super sencillo...........








 scripts fundamentales----------------

AVANCES MUY BUENOS



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()



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

ABANCES MUY BUENOS

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


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):

queue_free()


pass # Replace with function body.



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

ABANCES MUY BUENOS

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

extends RigidBody3D



func _ready():


pass # Replace with function body.


func _process(delta):


pass


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



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

ABANCERS MUY BUENOS AQUI INSTANCIA

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

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 CharacterBody3D


# Adding Animations

# ------------------------------------------------

# 1. Define Animations: Create new animations in Godot's animation tools.

# 2. Add Animation Nodes: Ensure 'AnimationPlayer' nodes exist for animated objects.

# 3. Update Parts Dictionary: In `_ready`, add new nodes to 'parts' dict, e.g., `"anim_player": $AnimationPlayer`.

# 4. Create Animation Methods: Write methods for new animations, e.g., `func perform_attack() -> void`.

# 5. Implement Animation Logic: In the methods, use `parts["anim_player"].play("your_animation_name")` to play animations.

# 6. Integrate with Existing Code: Add logic to trigger these animations (e.g., in `_input` or `_process` functions).

# 7. Test Animations: Ensure animations work as expected and integrate smoothly.

# 8. Optimize and Refine: Adjust timings, transitions, or other elements for best results.

#

# Example for Adding an Attack Animation:

# @onready var parts: Dictionary = {"head": $head, "body": $body, "anim_player": $AnimationPlayer, ...}

# func perform_attack() -> void: parts["anim_player"].play("attack_animation")

# func _input(event: InputEvent) -> void: if event is InputEventKey and event.pressed: perform_attack()

#

# Adjust steps based on your specific game needs and scenarios.



# Exported Variables

@export var sprint_enabled: bool = true

@export var crouch_enabled: bool = true

@export var base_speed: float = 5.0

@export var sprint_speed: float = 8.0

@export var jump_velocity: float = 4.0#ORIGINAL

#@export var jump_velocity: float = 0.1#MANIPULADO

@export var sensitivity: float = 0.1

@export var accel: float = 10.0

@export var crouch_speed: float = 3.0


# Member Variables

var speed: float = base_speed

var state: String = "normal"  # normal, sprinting, crouching

var gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity")

var camera_fov_extents: Array[float] = [75.0, 85.0]  # index 0 is normal, index 1 is sprinting

var base_player_y_scale: float = 1.0

var crouch_player_y_scale: float = 0.75


# Node References

@onready var parts: Dictionary = {

"head": $head,

"camera": $head/camera,

"camera_animation": $head/camera/camera_animation,

"body": $body,

"collision": $collision

}

@onready var world: SceneTree = get_tree()


func _ready() -> void:

parts["camera"].current = true


func _process(delta: float) -> void:

handle_movement_input(delta)

update_camera(delta)


func _physics_process(delta: float) -> void:

apply_gravity(delta)

handle_jump()

move_character(delta)


func _input(event: InputEvent) -> void:

if event is InputEventMouseMotion:

handle_mouse_movement(event)


# Movement Logic

func handle_movement_input(delta: float) -> void:

if Input.is_action_pressed("move_sprint") and !Input.is_action_pressed("move_crouch") and sprint_enabled:

if !$crouch_roof_detect.is_colliding(): #if the player is crouching and underneath a ceiling that is too low, don't let the player stand up

enter_sprint_state(delta)

elif Input.is_action_pressed("move_crouch") and !Input.is_action_pressed("move_sprint") and crouch_enabled:

enter_crouch_state(delta)

else:

if !$crouch_roof_detect.is_colliding(): #if the player is crouching and underneath a ceiling that is too low, don't let the player stand up

enter_normal_state(delta)


func enter_sprint_state(delta: float) -> void:

state = "sprinting"

speed = sprint_speed

parts["camera"].fov = lerp(parts["camera"].fov, camera_fov_extents[1], 10 * delta)


func enter_crouch_state(delta: float) -> void:

state = "crouching"

speed = crouch_speed

apply_crouch_transform(delta)


func enter_normal_state(delta: float) -> void:

state = "normal"

speed = base_speed

reset_transforms(delta)


# Camera Logic

func update_camera(delta: float) -> void:

match state:

"sprinting":

parts["camera"].fov = lerp(parts["camera"].fov, camera_fov_extents[1], 10 * delta)

"normal":

parts["camera"].fov = lerp(parts["camera"].fov, camera_fov_extents[0], 10 * delta)


# Animation Logic

func apply_crouch_transform(delta: float) -> void:

parts["body"].scale.y = lerp(parts["body"].scale.y, crouch_player_y_scale, 10 * delta)

parts["collision"].scale.y = lerp(parts["collision"].scale.y, crouch_player_y_scale, 10 * delta)


func reset_transforms(delta: float) -> void:

parts["body"].scale.y = lerp(parts["body"].scale.y, base_player_y_scale, 10 * delta)

parts["collision"].scale.y = lerp(parts["collision"].scale.y, base_player_y_scale, 10 * delta)


# Physics Logic

func apply_gravity(delta: float) -> void:

if not is_on_floor():

velocity.y -= gravity * delta


func handle_jump() -> void:

if Input.is_action_pressed("move_jump") and is_on_floor():

velocity.y += jump_velocity


func move_character(delta: float) -> void:

var input_dir: Vector2 = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")

var direction: Vector2 = input_dir.normalized().rotated(-parts["head"].rotation.y)

if is_on_floor():

velocity.x = lerp(velocity.x, direction.x * speed, accel * delta)

velocity.z = lerp(velocity.z, direction.y * speed, accel * delta)

move_and_slide()


# Input Handling

func handle_mouse_movement(event: InputEventMouseMotion) -> void:

if !world.paused:

parts["head"].rotation_degrees.y -= event.relative.x * sensitivity

parts["head"].rotation_degrees.x -= event.relative.y * sensitivity

parts["head"].rotation.x = clamp(parts["head"].rotation.x, deg_to_rad(-90), deg_to_rad(90))