Godot Version
4.3
Question
Godot keeps saying “Too few arguments for “rotated()” call. Expected at least 2 but received 1.” for my previously 2D code that Im trying to transfer into 3D.
Code:
extends CharacterBody3D
change export to @export and fix type declararions
@export_subgroup(“Properties”)
@export var speed : int = 320
@export var jump_speed : int = 700
@export var gravity : int = 4000
velocity is integrated in Character2D so this isn’t needed
but move the initialisation to zero to func ready
#var velocity = Vector2.ZERO
var is_jumping = false
var planets: Array
var current_planet: Node
var time_delta = 0
func _ready():
planets = get_node(“/root/Sector4D/Planets”).get_children()
current_planet = planets[0]
_get_closest_planet()
$Timer.start()
velocity = Vector3.ZERO
self.floor_max_angle = 180
$Timer.one_shot = true
$Timer.wait_time = 0.1
func get_input():
velocity.x = 0
if Input.is_action_pressed(“move_right”):
velocity.x += speed
if Input.is_action_pressed(“move_left”):
velocity.x -= speed
if Input.is_action_pressed(“move_up”):
velocity.z += speed
if Input.is_action_pressed(“move_down”):
velocity.z -= speed
func _physics_process(delta):
get_input()
var gravity_dir = current_planet.global_transform.origin - global_transform.origin
rotation = gravity_dir.angle() - PI/2
if !is_jumping:
velocity.y = 0
velocity.y += gravity * delta
velocity = velocity.rotated(rotation)
move_and_slide()
if is_on_floor():
is_jumping = false
if Input.is_action_just_pressed("ui_accept"):
$Timer.start()
is_jumping = true
velocity.y = jump_speed
func _get_closest_planet() → void:
var _closest_planet = current_planet
var smallest_distance : float = INF
for planet in planets:
var distance_to_planet : float = global_position.distance_to(planet.global_position)
if distance_to_planet < smallest_distance:
current_planet = planet
smallest_distance = distance_to_planet
func _on_timer_timeout() → void:
_get_closest_planet()