+1 vote

Hi, I try to make a ball that can bounce using Rigidbody2D. Code come from Kidscancode example

extends RigidBody2D

var dragging
var drag_start = Vector2()
var drag_end = Vector2()

func _input(event):
mode = RigidBody2D.MODE_RIGID
if event.is_action_pressed("LMB") and not dragging:
    dragging = true
    drag_start = self.position

if event.is_action_released("LMB") and dragging:
    dragging = false
    drag_end = get_global_mouse_position()
    var dir = drag_start - drag_end
    apply_impulse(Vector2(), dir * -6)

but when I try to control this ball in the air. I think the ball have some glitch that I don't want it.
here is simple

I need to control the ball to a force #2 vector but when the ball fly in the air, the ball have old force (I named that force #1)
Then, the ball will go to a result vector (but I don't want the ball go to that way)

I think I should remove/clear force #1, or use other way to control the ball (and get the better result)
what should I do? edit my script? or use other way. and what way I can use?
help me please

asked Jul 9 in Engine by MoNoSpaze (13 points)

Can you share the code you're using? It would also help if you elaborated a little on your desired behavior. Do you want the ball to zero-out force #1 as soon as the user inputs force #2, or do you want them to fade from one to the other somehow? It might be a little jarring for the user to have the ball jerk back and forth without respect to inertia.

I'm not quite getting what the problem is but you might need to use add_force(). apply_impulse() is like kicking a ball, if the ball is falling and you kick it dead center back up, it'll go up not sideways.

I think I share my code already.
I think I want the ball to zero-out force #1 as soon as the user inputs force #2.

You can zero the velocity to cancel out physics movement like that.

linear_velocity = Vector2.ZERO
apply_impulse(...)

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 How to use this Q&A? before posting your first questions.