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)