Exemple #1
0
 public void ParentToActor(ActorObject actor)
 {
     gameObject.transform.SetParent(actor.transform, false);
     gameObject.transform.localPosition = new Vector3(0, settings.heightInVR, 0);
     // Set Culling mask.
     foreach (Camera cam in gameObject.GetComponentsInChildren <Camera>())
     {
         cam.cullingMask  = -1; // show everything
         cam.cullingMask &= ~(1 << LayerMask.NameToLayer(actor.name));
     }
 }
Exemple #2
0
        void Blink(BlinkMsg msg)
        {
            ActorObject act = GetComponent <ActorObject>();

            if (act != null)
            {
                act.Blink(msg.darkTime, msg.fadeTime, msg.disable);
            }
            else
            {
                Debug.LogError(string.Format("{0}: Tried to blink but object is not an actor.", name));
            }
        }
Exemple #3
0
        void SetBrightness(FloatMsg msg)
        {
            ActorObject act = GetComponent <ActorObject>();

            if (act != null)
            {
                DisplayObject disp = act.display;
                if (disp != null)
                {
                    disp.currentBrightness = msg.value;
                }
                else
                {
                    Debug.LogError(string.Format("{0}: Tried to set screen brightness but object has no display attached.", name));
                }
            }
            else
            {
                Debug.LogError(string.Format("{0}: Tried to set screen brightness but object is not an actor.", name));
            }
        }
Exemple #4
0
        public void ProcessMovement()
        {
            if (!settings.isActive)
            {
                movement.Clear();
                smoothBuffer.Clear();
            }
            if (settings.isActive)
            {
                // Read inputs.
                #region Read Inputs.
                if (movement.counter > 0)
                {
                    lock (movement)
                    {
                        moveArcLengths = movement.Sum(); // sum only what has been added.
                        movement.Clear();
                    }
                }
                // log.
                if (settings.enableLogging)
                {
                    sphericalControllerMsg.name  = name;
                    sphericalControllerMsg.roll  = (int)(moveArcLengths.x * 1000);
                    sphericalControllerMsg.yaw   = (int)(moveArcLengths.y * 1000);
                    sphericalControllerMsg.pitch = (int)(moveArcLengths.z * 1000);
                    logger.logFile.Log("Spherical Controller", sphericalControllerMsg);
                }
                #endregion
                if (Actor != null)
                {
                    // Check if actor changed.
                    if (prevActor != Actor)
                    {
                        prevActor = Actor; ActorCharController = Actor.GetComponent <CharacterController>();
                    }
                    // Smooth input buffer.
                    #region Smooth input.
                    if (GetBufferSize(settings.inputSmooth) != smoothBuffer.bufferSize)
                    {
                        smoothBuffer = new ValueBuffer(GetBufferSize(settings.inputSmooth), true);
                    }
                    smoothBuffer.Add(moveArcLengths.x, moveArcLengths.y, moveArcLengths.z);
                    moveArcLengths = smoothBuffer.Average();
                    #endregion

                    // Input gain and calculate speed.
                    if (moveArcLengths.x > 0)
                    {
                        moveArcLengths.x *= settings.gain.strafeLeft;
                    }
                    else
                    {
                        moveArcLengths.x *= settings.gain.strafeRight;
                    }

                    if (moveArcLengths.y > 0)
                    {
                        moveArcLengths.y *= settings.gain.turnLeft;
                    }
                    else
                    {
                        moveArcLengths.y *= settings.gain.turnRight;
                    }

                    if (moveArcLengths.z > 0)
                    {
                        moveArcLengths.z *= settings.gain.backward;
                    }
                    else
                    {
                        moveArcLengths.z *= settings.gain.forward;
                    }

                    // If on path.
                    if (path != null)
                    {
                        float currentDist = path.path.GetClosestDistanceAlongPath(Actor.transform.position);
                        float newDist     = -moveArcLengths.z + currentDist;
                        // set path looping.
                        PathCreation.EndOfPathInstruction endofPath;
                        if (settings.loopPath)
                        {
                            endofPath = PathCreation.EndOfPathInstruction.Loop;
                        }
                        else
                        {
                            endofPath = PathCreation.EndOfPathInstruction.Stop;
                        }
                        // calculate position and heading.
                        Vector3 pos     = path.path.GetPointAtDistance(newDist, endofPath);
                        Vector3 pathRot = path.path.GetRotationAtDistance(newDist, endofPath).eulerAngles;
                        pathRot[2] = 0;
                        //update position.
                        if (Actor.isActive)
                        {
                            Actor.transform.position = pos;
                            Actor.transform.rotation = Quaternion.Euler(pathRot);
                        }
                    }
                    // if freely moving
                    else
                    {
                        moveHeading.y = moveArcLengths.y;
                        // Trajectory based heading.
                        #region Trajectory based heading.
                        float speed = Mathf.Sqrt(Mathf.Pow(moveArcLengths.x, 2) + Mathf.Pow(moveArcLengths.z, 2)) / Time.deltaTime;
                        if (speed > settings.trajectoryHeading.minSpeed)
                        {
                            float angle = Mathf.Atan(moveArcLengths.x / moveArcLengths.z) * Mathf.Rad2Deg; // angle between -90 to 90 degrees based on movement vector.
                            if (angle == 90 || angle == -90)
                            {
                                angle *= -1;
                            }                                                 // Edge cases (assume forward movement)
                            // Add angle offset
                            angle += settings.trajectoryHeading.angleOffsetBias;
                            if (angle > 90)
                            {
                                angle = 90;
                            }
                            if (angle < -90)
                            {
                                angle = -90;
                            }
                            // convert to scale factor
                            float rotFactor = angle / 90f; // 90 degrees is maximum rotation per second.
                                                           // convert to rotation
                            moveHeading.y += rotFactor * (settings.trajectoryHeading.maxRotPerSec * Time.deltaTime);
                        }
                        #endregion
                        // Apply translation in opposite direction according to heading.
                        if (Actor.isActive)
                        {
                            //Heading.
                            Actor.transform.Rotate(moveHeading, Space.Self);
                            //Translation.
                            moveArcLengths.x *= -1; moveArcLengths.y = 0; moveArcLengths.z *= -1;
                            ActorCharController.Move(Actor.transform.TransformVector(
                                                         moveArcLengths));
                        }
                    }
                }
            }
        }