// Update is called once per frame void Update() { // render when necessary; cord only changes when: // smoothing is happening, this instance is grabbed, and the end position has changed if (doSmooth && inHand == this && end.transform.position != endPos) { endPos = Vector3.SmoothDamp(endPos, end.transform.position, ref velocity, smoothing); Render(); //AkSoundEngine.SetRTPCValue("Tuning", tuning, grabber); } if (playerPos != player.position) { playerPos = player.position; // to get the effect that the sound is distributed along the length of the cord // place sound emitter at the point on the line nearest the player soundEmitter.transform.position = Linear.NearPointOnLine(startPos, endPos, playerPos); } // the wind object moves stochastically around the area (see Wind.cs) // wind position determines Vector3 nearToWind = Linear.NearPointOnLine(startPos, endPos, wind.position); float windIntensity = 1 / (Vector3.Distance(nearToWind, wind.position)); AkSoundEngine.SetRTPCValue("Wind", windIntensity, soundEmitter); }
// measure distance of this segment of cord from the player float DistanceFromGrabber() { Vector3 pos = grabber.transform.position; // calculate the point on centre line of the capsule nearest to the player Vector3 near = Linear.NearPointOnLine(start, end, pos); return(Vector3.Distance(near, pos)); }