Bullets speed dependent on position - try transform.basis_xform()!

Hello! I was recently having problems with regard to my Bullet/projectile speed changing depending on its location, rather than being independent of it. The reason for this was I did this

self.position += transform * Vector2(750,0) * delta; #Vector2(750,0) was my speed var. 

However, my bullet would change the magnitude of it’s speed depending on it’s position relative to the origin. Why was this happening? Because transform includes the origin in its 2x3 matrix. So, if instead you use the function transform.basis_xform(Vector2(750,0)), it uses the transform matrix without the origin. like this

self.position += transform.basis_xform(Vector2(750,0)) * delta; 

This solved the problem and made the magnitude consistent across all directions.

Anyway, just putting this here so people know about it in the search engines and stuff. Learned this on the Godot discord, but I’m trying to break the consolidation of information on discord.

How’s your version better than just doing this?

position += Vector2(750, 0) * delta

Edit: Ah, I guess it probably transforms the direction to always be “forward” when the body is rotated.

1 Like