I want the ball to go in the opposite direction and the first time it does that but every time after, it goes in a weird direction. Heres the code I have:
extends Area2D
export var mass = 2.0
const speed = 2
var shoot = false
var detect = false
var velocity = Vector2(0, 0)
func _process(delta):
if shoot:
velocity += gravity_vec*gravity*mass*delta
position += velocity*delta
rotation = velocity.angle()
func _input(event):
if Input.is_action_just_released("BUTTON_LEFT"):
var mousePos = get_local_mouse_position()
launched(-mousePos*speed)
detect = true
if Input.is_action_just_pressed(ui_end):
get_tree().reload_current_scene()
func launched(initial_velocity : Vector2):
shoot = true
velocity = initial_velocity
func _on_Ball_body_entered(body):
if body.name == "Floor" and detect:
shoot = false
detect = false
Im using an Area 2d for the node, I was trying to use a rigidBody but I couldn't find a way to use it like I wanted. But got the Area2D to work instead! If you can help, that would be great! Thank you