domingo, 5 de mayo de 2024

GDScript; w-a-s-d y flechas teclado , girar y mover un cañon CharacterBody3D;ampliado alante atras izquierda derecha arriba y abajo inclinacion de cañon....!!!!;

 extends CharacterBody3D




var rotate_speed = 10.1 




const SPEED = 5.0

const JUMP_VELOCITY = 14.5


# Get the gravity from the project settings to be synced with RigidBody nodes.

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




func _ready(): 


pass # Replace with function body.


func _physics_process(delta):


if not is_on_floor():

velocity.y -= gravity * delta


# Handle jump.

if Input.is_action_just_pressed("ui_accept") and is_on_floor():

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 = Input.get_vector("move_left", "move_right", "move_forward", "move_backward",)#PERFECTOOOOOOO

var input_dir = Input.get_vector("ui_left", "ui_right","A", "B",)# "A", "B" SOLO AMAGO PARA QUE NO BALLA ADELANTE A DETRAS

#var input_dir = Input.get_vector("A", "D", "W", "S")

var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()

if direction:

velocity.x = direction.x * SPEED

velocity.z = direction.z * SPEED

else:

velocity.x = move_toward(velocity.x, 0, SPEED)

velocity.z = move_toward(velocity.z, 0, SPEED)

move_and_slide()



var movimiento_vector = Vector3.ZERO  # Inicializar vector de movimiento


if Input.is_action_pressed("move_forward"):

rotate_x(0.01) # Mover en el eje X para rotar (negativo para abajo)

elif Input.is_action_pressed("move_backward"):

rotate_x(-0.01)   # Mover en el eje X para rotar (positivo para arriba)

elif Input.is_action_pressed("move_left"):

rotate_y(0.01)  # Mover en el eje Z para rotar (positivo para izquierda)

elif Input.is_action_pressed("move_right"):

rotate_y(-0.01) # Mover en el eje Z para rotar (negativo para derecha)


-------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------EXPLICACION: EN GODOT DESDE PROYECTO A CONFIGURACION PROYECTO SE HAN DE ASIGNAR LAS LETRAS move_left" SERIA LA -A-move_right" SERIA LA -D- Y ASI SUCESIVAMENTE, etc etc etc.....



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

ampliado alante atras izquierda derecha arriba y abajo inclinacion de cañon....!!!!!!!!

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

extends CharacterBody3D




var rotate_speed = 10.1 




const SPEED = 5.0

const JUMP_VELOCITY = 14.5


# Get the gravity from the project settings to be synced with RigidBody nodes.

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




func _ready(): 


pass # Replace with function body.


func _physics_process(delta):


if not is_on_floor():

velocity.y -= gravity * delta


# Handle jump.

if Input.is_action_just_pressed("ui_accept") and is_on_floor():

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 = Input.get_vector("move_left", "move_right", "move_forward", "move_backward",)#PERFECTOOOOOOO

var input_dir = Input.get_vector("ui_left", "ui_right","ui_up", "ui_down",)# "A", "B" SOLO AMAGO PARA QUE NO BALLA ADELANTE A DETRAS

#var input_dir = Input.get_vector("A", "D", "W", "S")

var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()

if direction:

velocity.x = direction.x * SPEED

velocity.z = direction.z * SPEED

else:

velocity.x = move_toward(velocity.x, 0, SPEED)

velocity.z = move_toward(velocity.z, 0, SPEED)

move_and_slide()



var movimiento_vector = Vector3.ZERO  # Inicializar vector de movimiento


if Input.is_action_pressed("move_forward"):

rotate_x(0.01) # Mover en el eje X para rotar (negativo para abajo)

elif Input.is_action_pressed("move_backward"):

rotate_x(-0.01)   # Mover en el eje X para rotar (positivo para arriba)

elif Input.is_action_pressed("move_left"):

rotate_y(0.01)  # Mover en el eje Z para rotar (positivo para izquierda)

elif Input.is_action_pressed("move_right"):

rotate_y(-0.01) # Mover en el eje Z para rotar (negativo para derecha)




No hay comentarios:

Publicar un comentario