Rotation world not working with player

Godot Version

4.4.1

Question

Im trying to make a game like Rotate 🕹️ Play on CrazyGames where u rotate the player to solve puzzles, I tried to make code that does this, but with turning the tile.set instead of the player because vectors are hard. I managed to make turning left with q work however turning right with e does not seem to work and I have no idea why. Anyone have a fix for this?

this is my code:
extends Node2D

@export var world: TileMap
@export var player: Ch@exportracterBody2D

func@export_ready() → void:
pass # Replace with function body.

var target_rotation = 0
var target_position_x = 0
var target_position_y = 0

func _process(delta: float) → void:
if Input.is_action_just_pressed(“rotate_player_left”) and player.is_on_floor():
target_rotation -= 90

if Input.is_action_just_pressed("rotate_player_right") and player.is_on_floor():
	target_rotation -= 270
	
	
world.rotation_degrees = target_rotation % 360 # wrapf(, 0.0, 360.0)

And for jumping:

extends CharacterBody2D

const SPEED = 120.0
const JUMP_VELOCIT@export = -300.0

@export var camera: Camera2D

func _physics@exportprocess(delta: float) → void:

Add the gravity.

if not is_on_floor():
velocity += Vector2(0, -600) * delta

# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
	velocity.y = JUMP_VELOCITY

#print("Hello, world!")
# Rotate with E (or whatever "rotate_level_right" is mapped to)


	  # rotate right 90°

# Get the input direction and handle the movement/deceleration.
var direction := Input.get_axis("ui_left", "ui_right")
if direction:
	velocity.x = direction * SPEED
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)

move_and_slide()

picture that shows that turning right does not work like i want it to:

In what way it doesn’t work?

it seems that you might misunderstand how the game might handle the rotation of world.

  • It looks like it is rotating the camera!!! not the world
  • The down gravity for the game changes to be from a y axis to a x axis so the order goes like this
    [y-gravity → x-grav→ y-grav(reversed) →x-grav(reversed)]
  • It is doing it every time the player pressed E
  • I feel rotating the camera and gravity and player sprite would be easier than turning the world around
1 Like

this could be the issue im dealing with, i first tried turning the sprite with camera and changing gravity but that didn’t work (bit to advanced for me since its my first game).

1 Like

Looking at it from my POV it feels like rotating the world would be more complex than just rotating sprite, camera, and gravity. It would take more code if you rotate the world because you would have to account for your level and everything else inside it except the player. But both methods are not easy either way, the only way to learn is to try though.

1 Like