Hello, Thank you for the reply. My apologies for not being specific.
I am adding a bullet prefab and shoot function to the Spineboy Object Oriented Example. I have added a ShootBullet() function to the PlayShoot() which is called when the ShootEvent occurs. The firingPoint position is an empty object which is using the bonefollower script to track "gun-tip".
To debug, I have put Debug.Log(firingPoint.position) as the last line in the ShootBullet() function.
With the mouse location held in place on screen and upon holding down the mouse button, the firingPoint position reads:
First Bullet: (-3.2, -1.8, 0.0)
Second Bullet and beyond: (-3.3, -1.0, 0.0)
The first Bullet firePoint seems to be location of the "gun-tip" when in the idle pose. The Second bullet and beyond fire point is correct.
I am sharing the relevant portions of the code below which is a truncated version to save you some eye strain. (my changes/additions are in bold)
using UnityEngine;
using System.Collections;
using Spine.Unity;
namespace Spine.Unity.Examples {
public class SpineboyBeginnerView : MonoBehaviour {
#region Inspector
[Header("Components")]
public SpineboyBeginnerModel model;
public SkeletonAnimation skeletonAnimation;
public float speed;
public float movement;
private Rigidbody2D rbody;
public AnimationReferenceAsset run, idle, aim, shoot, jump;
public EventDataReferenceAsset footstepEvent;
[Header("Audio")]
public float footstepPitchOffset = 0.2f;
public float gunsoundPitchOffset = 0.13f;
public AudioSource footstepSource, gunSource, jumpSource;
[Header("Effects")]
public ParticleSystem gunParticles;
#endregion
SpineBeginnerBodyState previousViewState;
public Transform firingPoint;
public GameObject bulletPrefab;
public Vector2 aimm;
public float bulletspeed = 15f;
void Start () {
if (skeletonAnimation == null) return;
model.ShootEvent += PlayShoot;
model.StartAimEvent += StartPlayingAim;
model.StopAimEvent += StopPlayingAim;
skeletonAnimation.AnimationState.Event += HandleEvent;
rbody = GetComponent<Rigidbody2D>();
}
void HandleEvent (Spine.TrackEntry trackEntry, Spine.Event e) {
if (e.Data == footstepEvent.EventData)
PlayFootstepSound();
}
#region Transient Actions
public void PlayShoot () {
// Play the shoot animation on track 1.
var shootTrack = skeletonAnimation.AnimationState.SetAnimation(1, shoot, false);
shootTrack.AttachmentThreshold = 1f;
shootTrack.MixDuration = 0f;
var empty1 = skeletonAnimation.state.AddEmptyAnimation(1, 0.5f, 0.1f);
empty1.AttachmentThreshold = 1f;
// Play the aim animation on track 2 to aim at the mouse target.
var aimTrack = skeletonAnimation.AnimationState.SetAnimation(2, aim, false);
aimTrack.AttachmentThreshold = 1f;
aimTrack.MixDuration = 0f;
var empty2 = skeletonAnimation.state.AddEmptyAnimation(2, 0.5f, 0.1f);
empty2.AttachmentThreshold = 1f;
gunSource.pitch = GetRandomPitch(gunsoundPitchOffset);
gunSource.Play();
//gunParticles.randomSeed = (uint)Random.Range(0, 100);
gunParticles.Play();
[b]ShootBullet();[/b]
}
[b]private void ShootBullet()
{
GameObject bullet = Instantiate(bulletPrefab, firingPoint.position, Quaternion.Euler(new Vector3(0f, 0f, 0f)));
var mousePosition = Input.mousePosition;
var worldMousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
aimm = new Vector2(worldMousePosition.x - firingPoint.position.x, worldMousePosition.y - firingPoint.position.y);
aimm.Normalize();
bullet.GetComponent<Rigidbody2D>().velocity = aimm * bulletspeed;
Debug.Log(firingPoint.position);
}[/b]
I have attached an image that will help to clarify.