Godot Version
4.4
Question
I am trying to make an Arkanoid clone. I got the logic for moving the paddle working but I also wanted the player to be able to tilt the paddle. The tilting works but when I move in the same direction as the tilt the paddle moves down for some reason. Moving the opposite direction of the tilt though still just goes along the x-axis. I am using the velocity property and move_and_slide(). Initially I thought maybe the velocity direction is affected by the rotation of the CharacterBody2D but everything I’ve read about it says it is global. I’m a little stumped on where I am going wrong here so any help would be great!
Because I am a new user I am not able to attach a video but here are some screen shots.
And here is my code
class_name Paddle extends CharacterBody2D
const SCENE_REF: PackedScene = preload("res://scenes/paddle.tscn")
const SPEED = 1000.0
const ROT_SPEED = 80
const ROT_ANGLE = 20
var useMouse = false
var target_rotation = 0
var tween = create_tween()
static func instantiate() -> Paddle:
var newScene = SCENE_REF.instantiate()
return newScene
func _ready() -> void:
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
tween.set_loops()
tween.tween_property($"Aim Line", "rotation_degrees", -35, 1).set_ease(Tween.EASE_OUT).from(-145)
tween.tween_property($"Aim Line", "rotation_degrees", -145, 1).set_ease(Tween.EASE_OUT)
tween.stop()
func _physics_process(delta: float) -> void:
# Rotate the paddle
var rotInput = Input.get_axis("turn_left", "turn_right")
if rotInput == 0:
rotation_degrees = move_toward(rotation_degrees, 0, ROT_SPEED * delta)
else:
rotation_degrees = clamp(rotation_degrees + rotInput * ROT_SPEED * delta, -ROT_ANGLE, ROT_ANGLE)
# Move the paddle
if useMouse:
var target = get_global_mouse_position()
target.y = position.y
velocity = position.direction_to(target) * SPEED
if position.distance_to(target) > 10:
move_and_slide()
else:
var direction := Input.get_axis("move_left", "move_right")
velocity.x = direction * SPEED
move_and_slide()
func EnableAimLine() -> void:
$"Aim Line".visible = true
tween.play()
func DisableAimLine() -> Vector2:
$"Aim Line".visible = false
tween.stop()
return Vector2.from_angle($"Aim Line".rotation)
