domingo, 25 de agosto de 2024

GDScript combinacion de movimientos por raton botones y por teclas del pc;

 extends MeshInstance3D


var is_rotating = false

var is_rotating2 = false

var is_rotating3 = false

var is_rotating4 = false


var speed = 11  # Adjust the speed as needed

var delta = 0.009

var delta2 = 0.009

var delta3 = 0.009

var delta4 = 0.009

var delta5 = 0.022





func _input(event):

if event is InputEventMouseButton:

if event.pressed and event.button_index == 1:

is_rotating = true

else:

is_rotating = false


if event.pressed and event.button_index == 2:

is_rotating2 = true

else:

is_rotating2 = false


if event.pressed and event.button_index == 3:

is_rotating3 = true

else:

is_rotating3 = false


if event.button_index == 3 and not event.pressed:

is_rotating4 = true

else:

is_rotating4 = false


if event is InputEventKey:

#if event.pressed and event.scancode == KEY_P:

if event.pressed and event.is_action("GRUADIRECCIONDERECHA-I-"):

translate(Vector3(speed * delta, 0, 0))  # Move forward


if event.pressed and event.is_action("GRUADIRECCIONIZQUIERDA-U-"):

translate(Vector3(-speed * delta2, 0, 0))  # Move forward

if event.pressed and event.is_action("GRUADIRECCIONALANTE-J-"):

translate(Vector3( 0, 0, speed * delta))  # Move forward


if event.pressed and event.is_action("GRUADIRECCIONATRAS-K-"):

translate(Vector3( 0, 0, -speed * delta))  # Move forward

if event.pressed and event.is_action("GRUADIRECCIONARRIBA-O-"):

translate(Vector3( 0, speed * delta5,0))  # Move forward

if event.pressed and event.is_action("GRUADIRECCIONABAJO-P-"):

translate(Vector3( 0, -speed * delta5,0))  # Move forward


func _process(delta: float) -> void:

if is_rotating:

rotate_y(0.009)


if is_rotating2:

rotate_y(-0.009)


if is_rotating3:

rotate_x(-0.0009)


if is_rotating4:

rotate_x(0.0009)


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

Explicacion: forma efectiva de mover un objeto que contiene la camara para visualizar desde muchos angulos mientras se juega, una viga transparente que en un extremo contiene la camara que tiene el player, el player es el padre pero con este script solo controlamos esa viga un MeshInstance3D, conseguimos que rote desde el centro en su eje "Y"  presionando boton izquierdo del raton , al mantener presionado hace el giro, si se presiona el derecho hace el giro al reves, tambien e conseguido que al presionar la rueda del raton se gire en el eje "X", al soltar gira en el eje "X" al reves y para detener el giro de a de pulsar cualquier otra tecla, por que el script al presionar se escribe asi.....y al soltar ....bueno lo podeis ver esta en verde el detalle

if event.pressed and event.button_index == 3:

is_rotating3 = true

else:

is_rotating3 = false


if event.button_index == 3 and not event.pressed:

is_rotating4 = true

else:

is_rotating4 = false



siguiendo la explicacion, eso es en lo referente al raton, para que el script funcione con teclas del pc ....en este caso hay que asignar las teclas que queremos utilizar para eso desde godot hay que dirijirse a....proyecto y desde hay...configuracion del proyecto ....desde hay mapa de entrada.....desde hay añadir nueva accion  ...ponerle un nombre....en el ejemplo     if event.pressed and event.is_action("GRUADIRECCIONIZQUIERDA-U-"):             esta accion funciona al presionar tecla"u".......................yo en principio queria hacerlo directamente presionando la tecla "u" pero solo lo e consegiodo con esta forma de trabajar Godot 4.3    en la 4.2 supongo funcionara de la misma forma.........tambien e aprendido el tema concepto de "var"    

en el ejemplo  var delta4 = 0.009

                        var delta5 = 0.022


añadiendo propiedades personalizadas a la velocidad de movimientos de los delta que me interesaban alterar.......La IA me a yudado a prender y entender conceptos de programacion de GDScript, creo que es un metodo muy bueno, yo de programacion apenas se hacer nada y me cuesta muchisimo esfuerzo, pero al final si algo te gusta pues sacas provecho.

sábado, 24 de agosto de 2024

Rotar un MeshInstance3D con el raton en eje"y" y en eje "x" mediante GDScript;

extends MeshInstance3D


var is_rotating = false

var is_rotating2 = false

var is_rotating3 = false

var is_rotating4 = false


# Called when the node enters the scene tree for the first time.

func _ready() -> void:

pass  # Replace with function body.




func _input(event):

if event is InputEventMouseButton:

if event.pressed and event.button_index == 1:

is_rotating = true

else:

is_rotating = false

if event is InputEventMouseButton:

if event.pressed and event.button_index == 2:

is_rotating2 = true

else:

is_rotating2 = false

if event is InputEventMouseButton:

if event.pressed and event.button_index == 3:

is_rotating3 = true

else:

is_rotating3 = false




if event is InputEventMouseButton:

if event.button_index == 3 and not event.pressed:

is_rotating4 = true

else:

is_rotating4 = false




func _process(delta: float) -> void:

if is_rotating:

rotate_y(0.009)

if is_rotating2:

rotate_y(-0.0009)

if is_rotating3:

rotate_x(-0.0009)

if is_rotating4:

rotate_x(0.0009)




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

Explicacion: Con este script giro hacia la izquierda un objeto MeshInstance3D en su eje "Y" presionando boton izquierdo, si presiono derecho gira a la derecha sobre si mismo mientras mantengo presionado, y si presiono boton central del raton gira en el eje "X" todo fluidamente, si suelto el boton central gira al contrario del eje "X"....y no para asta que vuelvo a presionar algun boton del raton........

Girar fluidamente y constantemente al presionar botones del raton; con GDScript;

 extends MeshInstance3D


var is_rotating = false

var is_rotating2 = false


# Called when the node enters the scene tree for the first time.

func _ready() -> void:

pass  # Replace with function body.




func _input(event):

if event is InputEventMouseButton:

if event.pressed and event.button_index == 1:

is_rotating = true

else:

is_rotating = false

if event is InputEventMouseButton:

if event.pressed and event.button_index == 2:

is_rotating2 = true

else:

is_rotating2 = false



func _process(delta: float) -> void:

if is_rotating:

rotate_y(0.0009)

if is_rotating2:

rotate_y(-0.0009)




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

En su eje "y" un MeshInstance3D un cubo en forma de viga que sujeta una camara en un extremo, hacemos que gire presionando botones del mouse..........

Al presionar el boton izquierdo del raton, gira suavemente y constantemente un MeshInstance3D en su eje "Y"; mientras se presiona; al soltar se detiene;

extends MeshInstance3D


var is_rotating = false


# Called when the node enters the scene tree for the first time.

func _ready() -> void:

pass  # Replace with function body.




func _input(event):

if event is InputEventMouseButton:

if event.pressed and event.button_index == 1:

is_rotating = true

else:

is_rotating = false


func _process(delta: float) -> void:

if is_rotating:

rotate_y(0.0009)



Al presionar boton izquierdo del raton un MeshInstance3D da un giro en eje "Y", con GDScript;

 extends MeshInstance3D


# Called when the node enters the scene tree for the first time.

func _ready() -> void:

pass  # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.

func _process(delta: float) -> void:

pass  # Replace with function body.


func _input(event):

if event is InputEventMouseButton:

if event.pressed and event.button_index == 1:  # Botón izquierdo del ratón

rotate_y(0.9)

jueves, 22 de agosto de 2024