Trajectory calculation always comes short

Godot Version



I am trying to calculate the force required to move the target to hand. I setup the calculation so that the object will arrive at the hand when the target is at it’s highest position and that the object arrives always in the same time. There is no dampening.

var acceleration = Vector3.ZERO
var move : Vector3 = (hand.global_position - target.global_position)
var move_xz : Vector2 = get_flat_vector(move)
#target_time is half of the travel time
var time_pow = pow(2*target_time, 2)
#gravity_scale is 1.0 on all objects
var y_gravity = 1/2 * 9.81 * target.gravity_scale * time_pow
acceleration.y = ((move.y + y_gravity) * 2) / time_pow
acceleration = set_vector_xz(move_xz.normalized() * (4*move_xz.length()/time_pow), acceleration)
target.apply_central_force(acceleration * target.mass)

it seems using 1/2 will calculate to 0 since both are ints and not floats

Can’t be bothered to figure out the actual calculations need for using forces so i will just use velocity. This is few cm off but it will do: var move : Vector3 = (target.global_position - global_position) linear_velocity = Vector3(move.x, (move.y + (0.5 * 9.8 * pow(target_time, 2))), move.z) / target_time

For the first code to work the highest spot couldn’t actually be the position of the hand, if I wanted a specific time for the object to travel. I wonder why I couldn’t see that earlier.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.