Reputation: 31
I have a skspritenode(ship) that is the parent node then it has a child skspritenode(gun) that rotates freely. The gun has a child called skspritenode(bullet). The bullet shoots from the gun in the direction the gun is facing and that is perfct.
The problem is when the ship moves or if the turret rotates after a bullet is fired the bullet moves and rotates with the ship and gun. Is there anyway to prevent this from happening?
Upvotes: 0
Views: 146
Reputation: 7176
Think of it this way: the ship is facing in a specific direction when it fires the bullet.
Once it fires the bullet, you wouldn't expect it to have any control over the bullet? If it turned around, the bullet should keep moving in the same direction (not stay directly in front of the ship).
This is a hint that the bullet should probably not have the ship as a parent node; it is an entity existing alongside the ship and not as part of it.
Once the bullet is fired, it should be in the same 'system' as the ship, so as @LearnCocos2D suggested it should share a parent with the ship.
Upvotes: 0
Reputation: 64477
Add the bullets to the ship's parent (or directly to the scene), just not the ship or the turret because that will make the position of the bullet relative to either one.
Upvotes: 0