Godot Version
4.6
Question
Hellooooo!
So i have this minigame im making where i want the player to be able to put together blocks, but theyre all scattered around everywhere. I want the player, while dragging a block, to be able to rotate it with the mouse wheel, but i cant figure out how to do that.
Heres the code that ive been struggling with:
extends StaticBody2D
var dragging = false
var of = Vector2(0,0)
var rotation_speed = 5
func _process(delta):
if dragging:
position = get_global_mouse_position() - of
if Input.is_action_just_pressed("Rotate down"):
#no idea what happens after that, ive experimented and it doesnt work
How would i make it so that, if you are dragging an object, you can rotate it with the mouse wheel?
extends StaticBody2D
var dragging = false
var of = Vector2(0,0)
var rotation_speed = 5
func _process(delta):
if dragging:
position = get_global_mouse_position() - of
var rotate_direction: float = Input.get_axis("rotate_left", "rotate_right")
rotation += rotate_direction * rotation_sensitivity * delta
1 Like
i got the error “Error at (12, 40): Identifier “rotation_sensitivity” not declared in the current scope.” :,D
Sorry, change it to rotation_speed. I just copied and pasted that code from another project. I also recommend you change the two action names to match yours. And I’d recommend using snake_case in your action names.
1 Like
Its alright!! Thank you!
But when i run the scene its not rotating when i scroll the mouse wheel down and up?
Try assigning keyboard keys to it. If it works with the keys, it’s the mouse wheel. If not, it’s something else.