I won’t mark this as a solution yet, but I will do my best to do this and post my efforts here.
Oh sorry and I sometimes don’t see everything. And I know you already probably have a plan but what if you just used and used the mouse to rotate the camera but added a delay. I am still a new dev so I probably am not the best person to ask… but I try.
it’s all good man, I am in the same boat. I have tried a lot of methods and I just figured I’d put my problem out there because I can’t seem to find a tutorial video or forum post specifically talking about what I am trying to do.
I wasn’t implying to lock the mouse to the center. If it was locked, you wouldn’t need to calculate its relative position like that.
You don’t need any special “methods”. It’s exactly the same as regular mouselook. Just need to establish the referential basis and always rotate from there, as opposed to continuous relative rotation in regular mouselook.
There. Use it wisely:
extends Camera3D
const SENSITIVITY := 0.004
const SENSITIVITY_CONSTRAINED := 0.0005
var center_basis: Basis
var constrained_mode := false
func _ready():
DisplayServer.mouse_set_mode(DisplayServer.MOUSE_MODE_CAPTURED)
func _input(event):
if event is InputEventMouseMotion:
var offset: Vector2
if constrained_mode:
offset = -(get_viewport().get_mouse_position() - get_viewport().get_visible_rect().get_center()) * SENSITIVITY_CONSTRAINED
global_basis = center_basis
else:
offset = -event.relative * SENSITIVITY
center_basis = global_basis
rotate(Vector3.UP, offset.x)
rotate(global_basis.x, offset.y)
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_RIGHT:
constrained_mode = event.is_pressed()
DisplayServer.mouse_set_mode(DisplayServer.MOUSE_MODE_CONFINED if constrained_mode else DisplayServer.MOUSE_MODE_CAPTURED)
It’s a normal camera look but when you hold the right mouse button it goes into constrained mode centered around the last looking direction from the normal mode.
Wow, this is awesome! Two things I would like to ask:
Is it possible to make the constrained the default? So I can just change camera angles with triggers but it still has the constrained effect?
Two and this more just me wondering, is there an easy way to make an interaction system with that, ala hovering the mouse over a mesh and it changes color and clicking it does something?
Regardless, what you’ve given me is more than I could ever ask for
Thank you so much!
The regular mouselook in the example is just to set the center basis around which the constrained look is happening, to demonstrate that constrain can indeed work around any arbitrary center basis. You can make it “default”, but need to set that center basis first in some way. If you want it to happen towards some fixed point/object in space, you can construct the 3 basis vectors directly from these 2 vectors using cross products:
- direction vector from the camera to the object
- global up vector (typically global y)
Or just use Basis.looking_at()
Since the mouse cursor operates normally, interaction can be done by the standard mouse picking recipe using a raycast.