Godot Version
4.3
Question
I am trying to code a player that moves in a slingshot fashion. I currently have it where if you click on the player and drag, a line is drawn from the player to the mouse but I can’t seem to add a max range to the line without the limit being a square around the character rather than a circle. I’m essentially hoping someone could help explain how to add a max length to a line2D.
I am very new to godot and would really appreciate some advice.
My current code is this:
extends RigidBody2D
@onready var rayCast2D = $RayCast2D
@onready var line = $Line2D
@onready var col = $CollisionShape2Dvar aimStart := Vector2.ZERO
var aimFinish := Vector2.ZERO
var pressed := false
var rad = 30
var dis = 0
var dir = 0func _physics_process(delta: float) → void:
rotation = 0
dis = line.points[0].distance_to(line.points[1])
dir = (aimFinish - aimStart).normalized()func _on_button_button_down() → void:
pressed = truefunc _on_button_button_up() → void:
pressed = falsefunc _input(event: InputEvent) → void:
if Input.is_action_just_pressed(“left_click”) and pressed == true:
aimStart = col.position
line.points[0] = aimStart
if Input.is_action_pressed(“left_click”) and pressed == true:
aimFinish = get_local_mouse_position()
line.points[1] = aimFinish
if Input.is_action_just_released(“left_click”) and rayCast2D.is_colliding() == true and pressed == true:
linear_velocity = ((aimStart - aimFinish)*3)
line.points[0] = Vector2.ZERO
line.points[1] = Vector2.ZERO