1 using System.Collections;
2 using System.Collections.Generic;
7 using AVR.Core.Attributes;
10 namespace AVR.Motion {
39 [Header(
"Movement type")]
60 [Header(
"Mode-specifics")]
69 public float fade_pause = 0.1f;
75 public float dash_speed = 30.0f;
78 private bool tp_in_progress =
false;
83 protected override void Start() {
85 if (!CameraFadeEffect) CameraFadeEffect = GetComponent<AVR_Effect>();
86 if (!ray) ray = GetComponentInChildren<AVR_MovementRay>();
87 ray.filter = movementRestrictor.isValidTpLocation;
93 if (IsOnline && !IsOwner)
return;
96 if(controller.inputManager.getEventStatus(Enable_event)) {
104 if(ray.
isVisible && ray.
objectHit && controller.inputManager.getEventStatus(Execute_event) && ray.isValid) {
110 float t = Time.time - dash_stime;
111 float inter =(t*dash_speed) / (Vector3.Distance(dash_origin, destination));
112 MoveRigToFeetLocation(Vector3.Lerp(dash_origin, destination, inter));
114 tp_in_progress =
false;
123 tp_in_progress =
true;
124 CameraFadeEffect.StartEffect();
125 yield
return new WaitWhile(()=>CameraFadeEffect.
isBusy());
126 yield
return new WaitForSeconds(fade_pause);
127 MoveRigToFeetLocation(destination);
128 CameraFadeEffect.EndEffect();
129 yield
return new WaitWhile(() => CameraFadeEffect.
isBusy());
130 tp_in_progress =
false;
138 CameraFadeEffect.StartEffect();
139 yield
return new WaitWhile(() => CameraFadeEffect.
isBusy());
142 dash_origin = playerRig.FeetInWorldSpace;
143 dash_stime = Time.time;
144 tp_in_progress =
true;
147 while(inter < 1.0f) {
148 yield
return new WaitForEndOfFrame();
149 inter = ((Time.time - dash_stime) * dash_speed) / (Vector3.Distance(dash_origin, destination));
150 MoveRigToFeetLocation(Vector3.Lerp(dash_origin, destination, inter));
153 CameraFadeEffect.EndEffect();
154 yield
return new WaitWhile(() => CameraFadeEffect.
isBusy());
155 tp_in_progress =
false;
163 if(tp_in_progress)
return;
165 destination = targetLocation;
167 switch(teleportMode) {
168 case TeleportModes.INSTANT : {
169 MoveRigToFeetLocation(destination);
172 case TeleportModes.FADE_COLOR : {
173 StartCoroutine(BlinkTeleport());
176 case TeleportModes.DASH : {
177 dash_origin = playerRig.FeetInWorldSpace;
178 tp_in_progress =
true;
179 dash_stime = Time.time;
182 case TeleportModes.FADE_DASH : {
183 StartCoroutine(FadeDash());
187 AVR_DevConsole.cwarn(
"The given teleportMode is not valid!",
this);
194 playerRig.MoveRigToFeetPosition(feet);
When using a MovementProvider, this scriptable object allows you to set rules for which surfaces qual...
IEnumerator FadeDash()
This coroutine is exectued when a fade-dash-movement is performed.
AVR_ControllerInputManager.BoolEvent Execute_event
Event which (if possible) executes the movement to target location. Can only ocurr if the ray is visi...
void MoveRigToFeetLocation(Vector3 feet)
AVR_MovementRestrictor movementRestrictor
Determines which surface is a valid teleport-location and which is not.
AVR_ControllerInputManager.BoolEvent Enable_event
Event which enables/shows the teleportation-ray.
TeleportModes
Modes of teleportation/movement. INSTANT: Instantly moves to the target position FADE_COLOR: Fades th...
Provides common teleportation/movement functionality to a controller
Sets the documentation html file inside of Packages/com.avr.core/Documentation/html of a given class...
AVR_MovementRay ray
Ray which is displayed to target a location.
AVR_SolidRay but, when an object is hit, the hit is either valid or invalid. The validity of the hit ...
RaycastHit hitPosition
Raycasthit where the ray hit something. Contains the last hit the ray did if AVR_SolidRay.objectHit is false. null if the ray hasn't hit a single object in its lifetime. /summary>
abstract bool isBusy()
True if the effect is starting/started or ending but not yet ended.
TeleportModes teleportMode
Modes of teleportation/movement. INSTANT: Instantly moves to the target position FADE_COLOR: Fades th...
bool objectHit
True if the ray hit some object this frame. Use AVR_SolidRay.hitPosition to get the respective Raycas...
AVR_Component specifically attatched to an AVR_Controller. Needs to have an AVR_Controller on this ga...
Represents a generic effect, such as fading a color on a camera.
void CommenceTeleport(Vector3 targetLocation)
Begins a movement towards target location
AVR_Effect CameraFadeEffect
CameraFadeEffect used when teleportmode is FADE_COLOR or FADE_DASH.
IEnumerator BlinkTeleport()
This coroutine is exectued when a blink-movement (INSTANT) is performed.
bool isVisible
Is this ray visible