Saltar al contenido

ejemplo de código de secuencia de comandos de movimiento 3d de godot

Ya no tienes que investigar más en otros sitios ya que estás al lugar correcto, contamos con la respuesta que buscas sin complicaciones.

Ejemplo 1: movimiento de plataformas de Godot

extends KinematicBody2D # The player is a kinematic body, hence extends Kine..

# Adjustable variables of the player
# export is used to allow to edit the values outside the script
export var speed = 500 # The speed of the character
export var gravity = 32 # The gravity of the character
export var jumpforce = 800 # The jump force of the character

var motion = Vector2.ZERO 

func _physics_process(delta): 
	
	# Player movement functions:
	if Input.is_action_pressed("ui_right"): # If the player enters the right arrow
		motion.x = speed # then the x coordinates of the vector be positive
	elif Input.is_action_pressed("ui_left"): # If the player enters the left arrow
		motion.x = -speed # then the x coordinates of the vector be negative
	else: # If none of these are pressed
		motion.x = lerp(motion.x, 0, 0.25) # set the x to 0 by smoothly transitioning by 0.25
	
	if is_on_floor(): # If the ground checker is colliding with the ground
		if Input.is_action_pressed("ui_up"): # And the player hits the up arrow key
			JumpSound.play() # Play the jump sound
			motion.y = -jumpforce # then jump by jumpforce
	
	motion.y += gravity + delta # Always make the player fall down
	
	motion = move_and_slide(motion, Vector2.UP)
	# Move and slide is a function which allows the kinematic body to detect
	# collisions and move accordingly

Ejemplo 2: movimiento en godot

#3d
extends KinematicBody

var speed = 200
var motion = Vector2()

func _physics_process(delta):
	if Input. is_action_pressed("ui_right"):
		motion.x += speed
	elif Input. is_action_pressed("ui_left"):
		motion.x -= speed
	elif Input. is_action_pressed("ui_up"):
		motion.z -= speed
	elif Input. is_action_pressed("ui_down"):
		motion.z += speed
	else:
		motion.x = 0
		

	move_and_collide(motion)

Eres capaz de asistir nuestro estudio ejecutando un comentario y dejando una puntuación te damos las gracias.

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *