Don't Starve Rotate Camera

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

Hello!, I need some help.
I’m trying to make a game based on my favorite game “Don’t Starve”. But I came across a problem.
Does anyone know any way to rotate the whole world, as it does in don’t starve?

Don’t starve Rotate:
https://drive.google.com/file/d/18wo_MImIHAC1g5JCOED96eto9zObU6WG/view?usp=sharing

My Game Rotate:
https://drive.google.com/file/d/11iSujuff_tw4tXb7I0gqB8u45kT1VLHk/view?usp=sharing

-Only my character rotates, and the camera
-Inverted Movement

I’m pretty sure it’s the camera that rotates not the whole world.

Dlean Jeans | 2020-02-29 01:53

Why you suppose?

Amigoimaginario | 2020-03-01 02:03

:bust_in_silhouette: Reply From: Amigoimaginario

After a long time thinking about an algorithm to solve this problem, I got where I wanted to, here’s my code in case anyone needs it

func get_input():
#Rotate Camera
var rotate = [Input.is_action_just_pressed("Rotate_Right") or Input.is_action_just_pressed("Rotate_Left"),-90]

if Input.is_action_just_pressed("Rotate_Right"):
	rotate[1] = 90

if rotate[0]:
	if $"RotateOffset".rotation_degrees.y >= 270 or $"RotateOffset".rotation_degrees.y <= -270 : #RotateOffset = Camera
		$"RotateOffset".rotation_degrees.y = 0
	else:
		$"RotateOffset".rotation_degrees.y += rotate[1]

Now, to disinvert the movement

var direction = Vector2(Input.get_action_strength("right") - Input.get_action_strength("left"),Input.get_action_strength("down") - Input.get_action_strength("up")).normalized()
var cd = Vector2(direction.x * speed,direction.y * speed).rotated($RotateOffset.rotation.y)
var rt = abs($RotateOffset.rotation_degrees.y)
if rt == 90 or rt == 270:
	cd = cd * -1
velocity = Vector3(cd.x,pos_y,cd.y)