miércoles, 28 de agosto de 2024

GDScript, movimientos y giros por mouse y teclado, presion de teclas de botones del mouse y de rotacion de su rueda;

 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.0002

var delta5 = 0.0002

var delta6 = 0.19

var delta7 = 0.19



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.pressed and event.is_action("mouse_rueda_arriba"):

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

if event.pressed and event.is_action("mouse_rueda_avajo"):

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


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.0009)


if is_rotating2:

rotate_y(-0.0009)


if is_rotating3:

rotate_x(-0.0009)


if is_rotating4:

rotate_x(0.0009)

No hay comentarios:

Publicar un comentario