Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | paczuszki |
func _physics_process(delta):
if velocity == Vector2(0,0):
move()
velocity.y +=10*delta
velocity = move_and_collide(Kappa*delta)
Line that not work is if velocity == Vector2(0,0):
function move
func move():
target=get_global_mouse_position()
height = get_global_mouse_position().y-global_position.y - 32
height = min(height,-32)
velocity =PhysicsHandler.projection(global_position,target,height)
PhysicsHandler
extends Node
class_name PhysicsHandler
static func projection (starting_position,end_position,height,gravity = 10):
var velocity = Vector2()
var displacement = end_position - starting_position
var time_up= sqrt(-2*height / float(gravity))
var time_down= sqrt(2*(displacement.y - height) / float(gravity))
velocity.y = -sqrt(-2*gravity*height)
velocity.x = displacement.x/float(time_up+time_down)
return velocity
Any idea what id dont work ?