Hi and greetings from Sweden!
I'm trying to shoot bullets from a weapon but can't get it right. The weapon is controlled by the keyboard.
My thought is to have a "barrel bone" for every gun attachment which is the bullet's spawn point, but I don't know how to do this properly.
My code so far:
public void Setup(SkeletonAnimation skeletonAnimation) {
this.skeletonAnimation = skeletonAnimation;
thompsonBarrel = this.skeletonAnimation.skeleton.FindBone("thompsonBarrel");
}
public void Shoot(bool isFacingRight) {
float speed = 1000.0F;
float x = thompsonBarrel.worldX;
float y = thompsonBarrel.worldY;
float rotation = thompsonBarrel.worldRotation;
bullet = (GameObject)Instantiate(bulletPrefab, new Vector3(x, y, 0), Quaternion.Euler(rotation, 0, 0));
//Add force
}
What should be in the Instantiate and add force?
Best regards,
joelwe