0 votes

First of all, sorry for my bad english, I'm learning.

My problem is, I have to throw a rigid body, like a ball in a Ballistic Curve, simulating a rotation (When I'm in the angle of 90 degrees, the ball should be throwing to the left, not to the up).

Example of the correct angle: https://drive.google.com/file/d/1a8H3GGz6RnY7RpZMa2rob76XsJTjCN94/view?usp=sharing

I'm using the current code:

extends Node


var angleStop
var radius = 30
var rpm = 4


func _on_Button_pressed():
var impulse; var lock
lock = Vector2(0, 0)

impulse = get_impulse_vector(angleStop, rpm, radius)
$groundBody/ballBody.apply_impulse(lock, impulse)

func get_impulse_vector(angleStop, rpm, size):

angleStop = 90 * PI/180
var fx = size * cos(angleStop) * radius * 0.10471975511965977 * rpm
var fy = -size * sin(angleStop) * radius * 0.10471975511965977 * rpm
var out = Vector2(fx, fy)

return out

With this code, the ball is thrown to the up, not to the left, someone can explain me why ?

in Engine by (12 points)

2 Answers

0 votes

Radians are used internally, and they assume 0 is to the right?

by (911 points)
0 votes

In your code snippet, the function get_impulse_vector always return Vector2(0, -1), so the direction is not LEFT but UP.

var fx = size * cos(angleStop) * radius * 0.10471975511965977 * rpm #fx = 0
var fy = -size * sin(angleStop) * radius * 0.10471975511965977 * rpm #fy = -1
var out = Vector2(fx, fy) //so, out = (0, -1)

you can change the angleStop to 0, fx to -fx to get the right direction.

by (126 points)
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.
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 webmaster@godotengine.org with your username.