0 votes

Im adding ne projectiles to my game, but found a problem. With larger projecties, we noticed that the are not properly rotated towards the moving direction. That was not visible when using a small capsule, but if we use a larger particle system with a trail and a head, you see how the fireball moves with head to a side or any other direction.

To instantiate the projectile I use a node in the weapon scene and this code:

var owner_forward = owner.get_actor().global_transform.basis.z #forward dir of plyer model

var forward

if item_mesh!=null:

    forward = item_mesh.global_transform.basis.z    #fwd dir of weapon model


    forward = owner_forward #if weapon has no model, we use player model

trace.global_transform.origin = item_mesh.find_node("flash").global_transform.origin + owner_forward*1.5

trace.transform.basis.z = item_mesh.find_node("flash").global_transform.basis.z 

trace.dir = Vector2(owner_forward.x, owner_forward.z) #movement direction of bullet

How can I make my projectile move in the direction the player is facing and also rotate to cpoint tat direction?

Godot version 3.4
in Engine by (185 points)

Does your projectile always move in a straight line
Or sometimes curve on the y axis based on weight and distance?

If possible can you show a picture of the problem and or intended result?

It moves in straight line during 3 seconds, then I destroy it. The movement works well, the problem is that I cant use different projectiles or projectiles with trails.

1 Answer

0 votes
#movement direction of bullet

var origin = global_transform.origin
var target = projectile_target.global_transform.origin
trace.dir = get_rotation_degrees(origin.direction_to(target))

if your projectile has homing abilities place the above in _process to keep updated

by (6,932 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 Frequently asked questions and 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 [email protected] with your username.