public void RegisterEventCallback(float time, CurveControlledBobCallback function, CurveControlledBobCallbackType type) { CurveControlledBobEvent curveControlledBobEvent = new CurveControlledBobEvent(); curveControlledBobEvent.time = time; curveControlledBobEvent.function = function; curveControlledBobEvent.type = type; events.Add(curveControlledBobEvent); events.Sort((CurveControlledBobEvent t1, CurveControlledBobEvent t2) => t1.time.CompareTo(t2.time)); }
/// <summary> /// Takes the speed the controller is going and will return a 3d vector which describes an offset which add on to local space position of camera /// Method will look through events in the list of events and if there is an event between current playHead and previous Playhead then need /// to make sure the event method is called. /// </summary> /// <param name="speed"></param> /// <returns></returns> public Vector3 GetVectorOffset(float speed) { xPlayHead += (speed * Time.deltaTime) / baseInterval; //speed that playHead moves dependent on speed of char controller yPlayHead += ((speed * Time.deltaTime) / baseInterval) * verticaltoHorizontalSpeedRatio; //how Y playhead moves compared to x playhead //Makes sure that if reach end of curve, loops back around to start if (xPlayHead > curveEndTime) { xPlayHead -= curveEndTime; } if (yPlayHead > curveEndTime) { yPlayHead -= curveEndTime; } // Loops through events in list and fetch the event currently processing and if not null, see if its vertical or horizontal event and we process them differently. for (int i = 0; i < events.Count; i++) { CurveControlledBobEvent ev = events[i]; if (ev != null) { if (ev.Type == CurveControlledBobCallbackType.Vertical) { //we know event is between the playhead positions or when prev position is larger than current playhead position (looped round) if ((prevYPlayHead < ev.Time && yPlayHead >= ev.Time) || (prevYPlayHead > yPlayHead && (ev.Time > prevYPlayHead || ev.Time <= yPlayHead))) { ev.Function(); } } else { if ((prevXPlayHead < ev.Time && xPlayHead >= ev.Time) || (prevXPlayHead > xPlayHead && (ev.Time > prevXPlayHead || ev.Time <= xPlayHead))) { ev.Function(); } } } } //the float of the curve at specified point in time float xPos = bobcurve.Evaluate(xPlayHead) * horizontalMultiplier; float yPos = bobcurve.Evaluate(yPlayHead) * verticalMultiplier; prevXPlayHead = xPlayHead; //updates the prev position of the playHeads to the new positions prevYPlayHead = yPlayHead; // //add this vector3 into the FPS Controller c;ass to the local space position of the camera to create space bobbing return(new Vector3(xPos, yPos, 0f)); }
public void RegisterEventCallback(float time, CurveControlledBobCallback function, CurveControlledBobCallbackType type) { CurveControlledBobEvent ccbeEvent = new CurveControlledBobEvent(); ccbeEvent.Time = time; ccbeEvent.Function = function; ccbeEvent.Type = type; _events.Add(ccbeEvent); _events.Sort( delegate(CurveControlledBobEvent t1, CurveControlledBobEvent t2) { return(t1.Time.CompareTo(t2.Time)); } ); }
public Vector3 GetVectorOffset(float speed) { _xPlayHead += (speed * Time.deltaTime) / _baseInterval; _yPlayHead += ((speed * Time.deltaTime) / _baseInterval) * _verticaltoHorizontalSpeedRatio; if (_xPlayHead > _curveEndTime) { _xPlayHead -= _curveEndTime; } if (_yPlayHead > _curveEndTime) { _yPlayHead -= _curveEndTime; } // Process Events for (int i = 0; i < _events.Count; i++) { CurveControlledBobEvent ev = _events[i]; if (ev != null) { if (ev.Type == CurveControlledBobCallbackType.Vertical) { if ((_prevYPlayHead < ev.Time && _yPlayHead >= ev.Time) || (_prevYPlayHead > _yPlayHead && (ev.Time > _prevYPlayHead || ev.Time <= _yPlayHead))) { ev.Function(); } } else { if ((_prevXPlayHead < ev.Time && _xPlayHead >= ev.Time) || (_prevXPlayHead > _xPlayHead && (ev.Time > _prevXPlayHead || ev.Time <= _xPlayHead))) { ev.Function(); } } } } float xPos = _bobcurve.Evaluate(_xPlayHead) * _horizontalMultiplier; float yPos = _bobcurve.Evaluate(_yPlayHead) * _verticalMultiplier; _prevXPlayHead = _xPlayHead; _prevYPlayHead = _yPlayHead; //Aggiungere zPos per ottenere la camminata Chicken Style return(new Vector3(xPos, yPos, 0f)); }
/// <summary> /// Method takes the events and sorts them into ascending order. Method is used to play an event (the footstep sound at 1.5 secs into curve) /// </summary> /// <param name="time"></param> /// <param name="function"></param> /// <param name="type"></param> //time falls between keyframes on curve, reference to function to be called public void RegisterEventCallback(float time, CurveControlledBobCallback function, CurveControlledBobCallbackType type) { CurveControlledBobEvent ccbeEvent = new CurveControlledBobEvent(); ccbeEvent.Time = time; ccbeEvent.Function = function; ccbeEvent.Type = type; events.Add(ccbeEvent); //add them to events list events.Sort( //store times in ascending order delegate(CurveControlledBobEvent t1, CurveControlledBobEvent t2) { return(t1.Time.CompareTo(t2.Time)); } ); }
public Vector3 GetVectorOffset(float speed) { _xPlayHead += (speed * Time.deltaTime) / _baseInterval; _yPlayHead += ((speed * Time.deltaTime) / _baseInterval) * _verticalToHorizontalSpeedRatio; //wrap it back aound to the start of the curve if (_xPlayHead > _curveEndTime) { _xPlayHead -= _curveEndTime; } if (_yPlayHead > _curveEndTime) { _yPlayHead -= _curveEndTime; } //Process Events for (int i = 0; i < _events.Count; i++) { CurveControlledBobEvent ev = _events[i]; if (ev != null) { if (ev.Type == CurveControlledBobCallbackType.VERTICAL) { if ((_prevYPlayHead < ev.Time && _yPlayHead >= ev.Time) || (_prevYPlayHead > _yPlayHead && (ev.Time > _prevYPlayHead || ev.Time <= _yPlayHead))) { ev.Function(); } } else { if ((_prevXPlayHead < ev.Time && _xPlayHead >= ev.Time) || (_prevXPlayHead > _xPlayHead && (ev.Time > _prevXPlayHead || ev.Time <= _xPlayHead))) { ev.Function(); } } } } float xPos = _bobCurve.Evaluate(_xPlayHead) * _horizontalMultiplier; float yPos = _bobCurve.Evaluate(_yPlayHead) * _verticalMultiplier; _prevXPlayHead = _xPlayHead; _prevYPlayHead = _yPlayHead; return(new Vector3(xPos, yPos, 0f)); }
public Vector3 GetVectorOffset(float speed) { xPlayHead += (speed * Time.deltaTime) / baseInterval; yPlayHead += ((speed * Time.deltaTime) / baseInterval) * verticalToHorizontalSpeedRatio; if (xPlayHead > curveEndTime) { xPlayHead -= curveEndTime; } if (yPlayHead > curveEndTime) { yPlayHead -= curveEndTime; } for (int i = 0; i < events.Count; i++) { CurveControlledBobEvent ev = events[i]; if (ev != null) { if (ev.type == CurveControlledBobCallbackType.Vertical) { if ((prevYPlayHead < ev.time && yPlayHead >= ev.time) || (prevYPlayHead > yPlayHead && (ev.time > prevYPlayHead || ev.time <= yPlayHead))) { ev.function(); } } else if ((prevXPlayHead < ev.time && xPlayHead >= ev.time) || (prevXPlayHead > xPlayHead && (ev.time > prevXPlayHead || ev.time <= xPlayHead))) { ev.function(); } } } float xPos = bobCurve.Evaluate(xPlayHead) * horizontalMultiplier; float yPos = bobCurve.Evaluate(yPlayHead) * verticalMultiplier; prevXPlayHead = xPlayHead; prevYPlayHead = yPlayHead; return(new Vector3(xPos, yPos, 0f)); }