Hi. I’ve been stuck for hours trying to attach my fmod Event to a moving object’s position. The idea is to hear a projectile passing by when the player is close to the trajectory. Here’s my code :
public void PiratePatternAudioObjectCreate()
{
m_shootFinalTarget = new GameObject("shootFinalTargetLocation");
m_lerpingObject = new GameObject("lerpingObject");
}
public void PiratePatternAudioObjectDestroy()
{
Destroy(m_shootFinalTarget);
Destroy(m_lerpingObject);
}
public void PiratePatternShootObstacle(Vector3 shootFinalTarget)
{
if(m_shootObstacleTimer <= 1)
{
PiratePatternAudioObjectDestroy();
PiratePatternAudioObjectCreate();
m_shootFinalTarget.transform.position = shootFinalTarget;
currentPos = m_boatController.Physics.transform.position;
targetPos = m_shootFinalTarget.transform.position;
RuntimeManager.PlayOneShotAttached(m_piratePatternShoot.Guid, m_boatController.Physics.gameObject);
RuntimeManager.PlayOneShotAttached(m_piratePatternShootObstacleHit.Guid, m_shootFinalTarget);
// RuntimeManager.PlayOneShotAttached(m_piratePatternShootWhoosh.Guid, m_lerpingObject);
m_piratePatternShootWhooshInstance = RuntimeManager.CreateInstance(m_piratePatternShootWhoosh);
m_piratePatternShootWhooshInstance.start();
m_piratePatternShootWhooshInstance.release();
}
m_lerpingObject.transform.position = currentPos;
float obstacleLenght = Vector3.Distance(m_boatController.Physics.transform.position, targetPos);
float speed = 40f;
m_shootObstacleTimer += 1;
if(m_shootObstacleTimer > 1)
{
currentPos = Vector3.MoveTowards(currentPos, targetPos, speed * Time.deltaTime);
RuntimeManager.AttachInstanceToGameObject(m_piratePatternShootWhooshInstance, m_lerpingObject);
if(Vector3.Distance(m_lerpingObject.transform.position, targetPos) < 0.1)
m_lerpingObject.transform.position = targetPos;
}
As the projectile is triggered, my function PiratePatternShootObstacle is called. It creates an object “m_lerpingObject” which is moving from the enemy to a hit point. What I want is to get my event to follow this object. In order to do so, I used the AttachInstanceToGameObject Function. While profiling, I can see that whenever the event is called, it fires really far away from the enemy, but in the same direction as my hit point, but I can’t figure out why.