Godot Version
Replace this line with your Godot version
Question
Ask your question here! Try to give as many details as possible.
I get this error:
Parser Error: No constructor of “Vector2” matches the signature “Vector2(float)”.
extends CharacterBody2D
class_name PlayerController
@onready var animation_player: AnimationPlayer = $Animation_Controls/AnimationPlayer
@onready var currenthealth: int = max_health
@onready var particles_player: CPUParticles2D = $Particles/CPUParticles2D
# Movement Variables
@export var acceleration := 2400.0
@export var speed : float = 300.0
@export var jump_force : float = -250.0
@export var jump_time : float = 0.25
@export var coyote_time : float = 0.075
@export var gravity_multiplier : float = 3.0
@export var max_health = 3
var direction = 0
var is_jumping : bool = false
var jump_timer : float = 0
var coyote_timer : float = 0
var can_control : bool = true
var can_take_damage : bool = true
func _physics_process(delta: float) -> void:
if not can_control: return
# Add the gravity.
if not is_on_floor() and not is_jumping:
velocity += get_gravity() * gravity_multiplier * delta
coyote_timer += delta
else:
coyote_timer = 0
# Handle jump.
if Input.is_action_just_pressed("Jump") and (is_on_floor() or coyote_timer < coyote_time):
particles_player.emitting = true
velocity.y = jump_force
is_jumping = true
elif Input.is_action_pressed("Jump") and is_jumping:
velocity.y = jump_force
if is_jumping and Input.is_action_pressed("Jump") and jump_timer < jump_time:
jump_timer += delta
else:
is_jumping = false
jump_timer = 0
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
direction = Input.get_axis("Left", "Right")
velocity.x = move_toward(velocity.x, direction * speed, acceleration * delta)
move_and_slide()
func handle_danger(damage_amt : int, invincible_time : float = 0.0, ignore_invincible : bool = false) -> void:
if !can_take_damage and !ignore_invincible:
return
currenthealth -= damage_amt
if currenthealth == 0:
velocity.x = 0
print("You Died")
visible = false
can_control = false
await get_tree().create_timer(1).timeout
reset_player()
return
if invincible_time > 0.0:
can_take_damage = false
var invincible_tween = create_tween().set_trans(Tween.TRANS_SINE)
invincible_tween.tween_property(%Sprite2D, "modulate:a", 0.5, invincible_time/4.0)
invincible_tween.chain().tween_property(%Sprite2D, "modulate:a", 1.0, invincible_time/4.0)
invincible_tween.chain().chain().tween_property(%Sprite2D, "modulate:a", 0.5, invincible_time/4.0)
invincible_tween.chain().chain().chain().tween_property(%Sprite2D, "modulate:a", 1.0, invincible_time/4.0).finished.connect(_reset_can_take_damage)
func _reset_can_take_damage() -> void:
can_take_damage = true
func reset_player() -> void:
currenthealth = 3
velocity.x = 0
***PlayerController.global_position = Vector2(3.0 -63.0)*** -- here is the problem
visible = true
can_control = true