Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var yaw = 0
- var pitch = 0
- var in_motion = false
- var mouse_motion_scale = 2.5
- var mouse_motion = Vector2()
- var left_mouse_dow = false
- var right_mouse_dow = false
- var middle_mouse_dow = false
- func _input(event):
- if event.type == InputEvent.MOUSE_MOTION:
- #mouse_motion = event.speed / get_viewport().get_rect().size * mouse_motion_ratio
- mouse_motion = event.relative_pos / get_viewport().get_rect().size * mouse_motion_scale
- elif event.type == InputEvent.MOUSE_BUTTON:
- if event.button_index == 1:
- left_mouse_dow = event.pressed
- elif event.button_index == 2:
- right_mouse_dow = event.pressed
- in_motion = event.pressed
- elif event.button_index == 3:
- middle_mouse_dow = event.pressed
- func _process(delta):
- var transf = get_transform()
- if right_mouse_dow:
- if in_motion:
- yaw += mouse_motion.x * PI
- if yaw<-PI:
- yaw = PI+PI+yaw
- else:
- if yaw>PI:
- yaw -= PI + PI
- pitch += mouse_motion.y * PI
- if pitch<-PI:
- pitch = PI+PI+pitch
- else:
- if pitch>PI:
- pitch -= PI + PI
- var tr = Transform().rotated(Vector3(0,1,0),yaw).rotated(Vector3(1,0,0),pitch)
- #tr.origin = get_transform().origin
- transf.basis = tr.basis
Advertisement
Add Comment
Please, Sign In to add comment