moving mouse while running around

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ragacakaci

when i move around i cant look around i cant do both aat once what should i do?

:bust_in_silhouette: Reply From: Gluon

If you connect your camera to the mouse you could have a separate moving sprite and the ability to move the camera around. You would need some code to check if the sprite is still on the screen if you want to limit the camera in that way though.

can you show me exampe of coding iam still new to this

ragacakaci | 2022-12-01 19:02

This forum is really for answering specific questions I cannot write all the code for you but I can give some pointers to try to help.

If you have something like this attached to the camera in a scene as a script;

var DistanceToCharacter = 0

func _input(event: InputEvent) -> void:
    if event is InputEventMouseMotion:
        var move = event.position - get_viewport().size * 0.5
        if move.length() < DistanceToCharacter:
            self.position = vector2(0, 0)
       else:
            self.position = move.normalized() * (move.length() * DistanceToCharacter) * 0.5

this would allow you to set the camera to follow the mouse. If you then tie the variable DistanceToCharacter to some code which checks how far it is from your sprite it will allow you to control the camera the way you want. Or at least it should, I havent tested this its just how I would program it.

Gluon | 2022-12-01 19:16