This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

First of all, hi!

I'm new to this engine, but have been using GMS for some time. I searched for a couple of days, and have not found my answer anywhere on the internet.

My goal is to rotate the camera with the player, who's walking in a top-down-shooter style [eg. Robotron2084]. I want the player to appear stationary relative to camera.

So in a sense use lookat() to follow the mouse pointer. I can do it with buttons, like A and D to rotate a camera. But that's not the point. I also tried using calculated angles to add or subtract to the player and camera rotation (based on getlastmousespeed < or > 0). But it was really glitchy, I must have been doing something wrong.

Here's my scene hierarchy. The camera follows the player via the script.

Here's my poor visual representation, I apologise for the bad photoshop. I hope it helps.
enter image description here

I probably missed some vital detail, if I did please let me know. Thanks in advance! :)

Godot version 3.3.3
in Engine by (20 points)

Is there any reason you can't have the camera as the child of the player? It will be able to rotate automatically that way.

Unfortunately when I do that it constantly spins around. I use look_at(get_global_mouse_position()) on player script to rotate him.

2 Answers

0 votes
Best answer

I did it, so here's the solution for someone googling this stuff.

  1. first I use the _input() built in function
  2. then I check whether the event is a mouse movement
  3. and finally I rotate the player using "relative" property of the "InputEventMouseMotion class and multiply it by some floating point number to get a less sensitive controls

func _input(event: InputEvent) -> void: if event is InputEventMouseMotion: self.rotation += deg2rad(event.relative.x) * mouseSensitivity

by (20 points)
+1 vote

I think the issue is the controls. Since you're rotating the player to face the mouse pointer, the player will never stop rotating since the mouse pointer will always be the same location relative to the player. Instead, you should rotate the player based on the movement of the mouse.

by (8,580 points)

Thanks for Your assistance exuin!
I tried something like this on the player, with the camera set as a child node:

func _input(event: InputEvent) -> void:
mouseSpeed = Input.get_last_mouse_speed()
if mouseSpeed.x > 0:
    self.rotation += abs(mouseSpeed.x) / 15000
elif mouseSpeed.x < 0:
    self.rotation -= abs(mouseSpeed.x) / 15000

However no matter how I tweak the movement number it's divided by it's jittery and lags. I don't know how to describe it, but it feels as though the mouse sensor was dirty. Which it's not. :) And it's not the fps, the walking is smooth.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.