How to throw object along Bezier Curve. how to make arc projectile

Godot Version

<stable4.2>

Question

<Im trying to make enemy throw object toward player. How do you use _quadratic_bezier() to move characterbody2d to player? Right now I have enemy position (doesnt move) and player global position (target point) but i have no idea how to use _quadratic_bezier() and apply velocity and gravity.>

Last time I did this, I used a curve in the editor and set the projectile’s Y position to be a point on the curve (given a start/end position), e.g.

image

translation = global_translation.move_toward(end_position, move_speed * delta)
translation.y = curve.interpolate(distance_normalised)
global_translation = translation

distance_normalised is 1 - current_distance / total_distance.

how exactly do I add curve to characterbody2d? and what is translation?

The Curve is an export in the script, e.g. @export var curve: Curve - you can then assign a curve resource in the editor. translation is a Vector3 that has the value of the global_translation/global_position (3.5/4) (I posted code from a 3.5 game, sorry).

The code is working on a Spatial/Node3D but the same principle applies to 2D.

i think I should give up on this. I have not enough amount of knowledge and skill to implement that. there seems not many 2d arc projectile tutorial for godot…

You are in luck. I just saw this tutorial on Youtube https://www.youtube.com/watch?v=lLIUjSdBKlo&t=2s

The only thing to note is that, when you manually change a CharacterBody’s position, it will mess up the physics collisions.

1 Like

Don’t do that. Give the tutorial posted a go and see how you get on (as a side-project); there’s certainly a lot to learn and it might not be as easy as you thought (certainly getting a realistic arc or something resembling physics might be tough versus ‘just enough’) but DO stick with it.

by following some yt tutorial, i was able to make area2d that move with bezier curve. but as soon as player node is added to the scene, the speed and angle of it gose weird (speed will increase and angle will be changed). any idea why?

This is fine…
ezgif-2-0b0ec96266
but as soon as player node added…