Topic was automatically imported from the old Question2Answer platform.
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?
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)