So I was helped to solve how to move in the rotated direction using Vector2(0, 120).rotated(rotation), however the issue is that I need to change the Vector2 based on if I am moving along the x axis or y axis.

Example distance on x axis is 120 between tiles, distance on y is 105.

Is there a way to move in the direction of the rotation but to check for y or x axis and adjust the Vector2() accordingly? Here is my code thus far.

func _process(_delta):
var curr_pos = the_object.position
if Input.is_action_just_pressed("accelerate"):
the_object.global_position = curr_pos + Vector2(120,0).rotated(rotation)
if Input.is_action_just_pressed("decelerate"):
the_object.global_position = curr_pos + Vector2(-120,0).rotated(rotation)
if Input.is_action_just_pressed("rotate_left"):
rotation_degrees -= 90
if Input.is_action_just_pressed("rotate_right"):
rotation_degrees += 90

  • Kojack replied to this.
  • xRegnarokx I'd do it like this:

    func _process(_delta):
    	var curr_pos = the_object.position
    	if Input.is_action_just_pressed("accelerate"):
    		the_object.global_position = curr_pos + Vector2(1,0).rotated(deg_to_rad(rotation_degrees)) * Vector2(120,105)
    	if Input.is_action_just_pressed("decelerate"):
    		the_object.global_position = curr_pos + Vector2(-1,0).rotated(deg_to_rad(rotation_degrees)) * Vector2(120,105)
    	if Input.is_action_just_pressed("rotate_left"):
    		rotation_degrees -= 90
    	if Input.is_action_just_pressed("rotate_right"):
    		rotation_degrees += 90

    So the rotating vector is measured in tiles, then after rotation it is scaled by 120,105.
    (deg_to_rad is Godot 4. Godot 3 uses degToRad)

    My thought is I could use two counters attached to left and right inputs that go up by a number that by using counter % # == # if I calculate two numbers that can create a repeating unique pattern of 4 and just give 4 move commands attached to those unique numbers.

    Example: 2 increasing by 2 each rotation left and decreasing by 2 each rotation right creates a pattern of 6

    Lcount % 3 and 4 creates a pattern of (2,2)(1,0)(0,2)(2,0)(1,2)(0,0) so if I were to do that but with 4 repeating unique patterns with

    If... Lcount % 3 == 2 and Lcount % 4 == 2 (move)

    I'm not at all sure I understand you, but could you multiply the final position by the ratio vector?

    pos *= Vector2(120, 105) / 120.0

    xRegnarokx I'd do it like this:

    func _process(_delta):
    	var curr_pos = the_object.position
    	if Input.is_action_just_pressed("accelerate"):
    		the_object.global_position = curr_pos + Vector2(1,0).rotated(deg_to_rad(rotation_degrees)) * Vector2(120,105)
    	if Input.is_action_just_pressed("decelerate"):
    		the_object.global_position = curr_pos + Vector2(-1,0).rotated(deg_to_rad(rotation_degrees)) * Vector2(120,105)
    	if Input.is_action_just_pressed("rotate_left"):
    		rotation_degrees -= 90
    	if Input.is_action_just_pressed("rotate_right"):
    		rotation_degrees += 90

    So the rotating vector is measured in tiles, then after rotation it is scaled by 120,105.
    (deg_to_rad is Godot 4. Godot 3 uses degToRad)

      Kojack Thanks so much! That is so much more straight forward then my well it works work around method that'd require 4 if/else statements for accelerate and again for decelerate haha!

      It also works with my desire to eventually make it hexagonal movement as well! So thanks so much, for the moment I don't have to figure out anything complicated to move on hex grid. Though maybe eventually I'll have to optimize it, but it gives me a base to test some other things that I want to be able to do.

      DaveTheCoder Oops. I even had the manual open to it at the time and still typed it wrong. 🙂