This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Simple top down mini golf game. im using a rigidbody2d as a ball, and a ray that points from the ball to the mouse. i use applycentralforce towards the mouse position (normalized) * speed. you can see this works fine at first. the ball goes in the direction of the ray. once it gets rotated it doesnt.
enter image description here

I tried changing the rigidbody mode to character but it sticks to the wall to much. I tried having a position node be the bigining of the ray and setting its rotation to 0 every frame but that didnt work either. Here is my scene tree and code. all code is in the "Planet" wich is the rigidbody ball.
enter image description here

extends RigidBody2D

const max_length = 2000
onready var beam = $Beam
onready var end = $end
onready var ray = $RayCast2D
onready var begin = $begin

onready var my_line = $Line2D
export var shot_speed = 10
export var default_speed = 10

func _ready():
    shot_speed = default_speed

func _physics_process(delta):

func _handle_ray():
    var mouse_pos = get_local_mouse_position()
    var max_cast_to = mouse_pos.normalized() * max_length
    ray.cast_to = max_cast_to
    if ray.is_colliding():
        end.global_position = ray.get_collision_point()
        end.global_position = ray.cast_to
    beam.rotation = ray.cast_to.angle()
    beam.region_rect.end.x = end.position.length()

    if Input.is_action_pressed("Fire"):
        shot_speed += 10
    if Input.is_action_just_released("Fire"):
        apply_central_impulse(ray.cast_to.normalized() * shot_speed)
        shot_speed = default_speed

Hopefully thats enough info. Thank Y'all in advance

Godot version 3.5 Stable
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.