extends AnimationPlayer
func _on_animation_finished(anim_name):
if anim_name == "Armature|mixamo_com|Layer0":
# Reinicia la animación
play("Armature|mixamo_com|Layer0")
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 AnimationPlayer
func _on_animation_finished(anim_name):
if anim_name == "Armature|mixamo_com|Layer0":
# Reinicia la animación
play("Armature|mixamo_com|Layer0")
pass # Replace with function body.
La clave del problema es añadirle el esqueleto, y esta en los circulitos que se ponen en las extremidades, del personaje personalizado, primero has de subir tu personaje a Mixamo en formatos fbx o obj yo los e probado los dos, y de hay desde Mixamo se elige una vez has subido tu personaje ,una animacion y cuando lo a admitido bien y has colocado los circulos en las extremidades del personaje, lo pasas a blebder y desde blender lo exportas a Godot en formato glb.......
En resumen, orden de los pasos que e trabajado yo.......
1- maquehuman.--formatos --obj o fbx--yo use esqueleto de tipo game generico....
2-exportar a Mixamo- colocar los circulitos nen las extremidades
3-exportar a blender---para que desde blender lo transforme todo a formato--- glb
4-exportar a Godot4.2--formato ---glb
extends Node3D
# Variables para controlar si la animación está activa y el nombre de la animación actual
var is_animating = false
var anim_name = ""
# Called when the node enters the scene tree for the first time.
func _ready():
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
# Reproduce la primera animación al presionar la tecla "M"
if Input.is_action_pressed("ui_up"):
if not is_animating:
$AnimationPlayer.play("Armature|mixamo_com|Layer0")
anim_name = "Armature|mixamo_com|Layer0"
is_animating = true
# Reproduce la segunda animación al presionar la tecla "N"
elif Input.is_action_pressed("ui_down"):
if not is_animating:
$AnimationPlayer.play("otra/otramas")
anim_name = "otra/otramas"
is_animating = true
# Evita repetir la animación mientras se mantiene presionada la tecla
elif is_animating and not Input.is_action_pressed(anim_name):
is_animating = false
Primero pondre dos ejemplos de script GDScript que sirven para que al pulsar las teclas de flecha se active la animacion dos ejemplos con dos teclas diferentes,,,,
extends Node3D
# Variable para controlar si la animación está activa
var is_animating = false
# Called when the node enters the scene tree for the first time.
func _ready():
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
# Reproduce la animación al presionar la tecla "M"
if Input.is_action_pressed("ui_down"): # Reemplaza "ui_accept" con el código de acción real de la tecla "M"
if not is_animating:
$AnimationPlayer.play("Armature|mujerandaa30fps|default")
is_animating = true
# Evita repetir la animación mientras se mantiene presionada la tecla
elif is_animating and not Input.is_action_pressed("ui_down"):
is_animating = false
extends Node3D
# Variable para controlar si la animación está activa
var is_animating = false
# Called when the node enters the scene tree for the first time.
func _ready():
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
# Reproduce la animación al presionar la tecla "M"
if Input.is_action_pressed("ui_right"): # Reemplaza "ui_accept" con el código de acción real de la tecla "M"
if not is_animating:
$AnimationPlayer.play("Armature|zombietictocchica|default")
is_animating = true
# Evita repetir la animación mientras se mantiene presionada la tecla
elif is_animating and not Input.is_action_pressed("ui_right"):
is_animating = false
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
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))
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.