How to make a bullet be top heavy, and rotate mid air.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Jax1221

Hi there, and thanks for taking the time to read (and hopefully answer) this question. I have a very simple project, consisting of only a player, a gun, and a tile set. The gun is capable of shooting bullets, I have that part working fine. My problem isn’t with the gun, but with the bullets. The gun always points towards the mouse, and its position and rotation is stored so that the bullets that are shot out of it are orientated correctly. This works fine when the bullets are shot in a straight line without gravity, but after I added gravity it looks a little wonky because it doesn’t rotate around the center of mass like a normal projectile would. For context on how I want it to look, think of like a badminton shuttlecock, where it rotates around the center of mass. This is probably due to the fact that I set the initial rotation of the object in a start function:

func start(pos, dir):
rotation = dir #dir and pos are variables that reference the rotation and 
position = pos #position of the gun.
velocity = Vector2(speed, 0).rotated(rotation)

That’s really all there is. Conceptually it’s probably really easy, but since I’m still fairly new to GDscript I can’t seem to figure it out for the life of me. Any and all help will be much appreciated!

:bust_in_silhouette: Reply From: camarones

Hi there. Presumably your bullet is made of several nodes e.g.:

  • Rigidbody2D
    • CollisionShape2D
    • Sprite

The centre of gravity is determined by the CollisionShape2D. If you move the Sprite relative to the CollisionShape2D, it will appear to be top-heavy. Using your shuttlecock example, if the Sprite of the shuttlecock is shifted so that the heavy foam ball is over the centre of the CollisionShape2D. This will make it look like it rotates around the foam ball, although the centre of mass will not have really changed.

If you do want to have an object where the centre of gravity is not in the centre of the shape, look into using multiple physics nodes each with different masses, or add_force and apply_impulse, which allow you to apply drag/gravitational forces offset from the centre of gravity.