0 votes

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!

in Engine by (17 points)

1 Answer

0 votes

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 addforce and applyimpulse, which allow you to apply drag/gravitational forces offset from the centre of gravity.

by (108 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 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 webmaster@godotengine.org with your username.