Shooting ball out of a cannon

Hi, everyone I am creating a game but I don’t know how to get the ball getting shot through and out of the cannon. It currently launches from a point in the space close to the cannon.
I’ve linked my github repo and attached a screenshot

I think the issue is mainly due to the cannon’s local space not being properly aligned with the world space, which makes the spawn position feel offset.

You just need to make sure the cannon’s transform (position + rotation) is correctly aligned with the physics/world space. If those aren’t in sync, the projectile will appear to spawn from a nearby point instead of the barrel.

Here’s what I changed for you to check:

  • Added a barrel helper object to mark the muzzle position

  • Used barrel.getWorldPosition() for accurate spawn point

  • Used cannon.getWorldDirection() to get correct firing direction

I’ve also attached a screenshot for better clarity.

If you want, I can push these changes directly to your repo.

I appreciate the help, I didn’t realise you have to align the cannons transform with the physics space, I thought you have to experiment with random points. It would be helpful if you could push change to the repo.

Yeah, that’s actually a core concept when working with physics engines, your visual objects and physics world need to stay aligned, otherwise you’ll see offsets like this.

I’ve pushed the changes by forking your repository. Please take a look.

Thank you.