Пример #1
0
 public void ShakeIfOnCamera(Transform _transform)
 {
     if (CameraHelper.CameraContainsPoint(_transform.position))
     {
         Shake();
     }
 }
Пример #2
0
        //The meat of RexPhysics. Moves the object and handles colliding with surfaces
        public void StepPhysics()
        {
            box = GetRectAtPosition(properties.position);
            bool isOnCamera      = CameraHelper.CameraContainsPoint(transform.position, 6.0f);
            bool willStepPhysics = (!isOnCamera && raycastAmounts.disablePhysicsWhenOffCamera) ? false : true;

            if (willStepPhysics)
            {
                TranslateForMovingPlatform();

                if (Mathf.Abs(properties.acceleration.x) > 0.0f && Mathf.Abs(properties.velocityCap.x) > 0.0f)
                {
                    ApplyAccelerationX();
                }

                ApplyDecelerationX();

                CheckHorizontalCollisions((properties.velocity.x + properties.externalVelocity.x) * PhysicsManager.Instance.fixedDeltaTime);

                ApplyHorizontalVelocity();

                if (willSnapToFloorOnStart)
                {
                    AnchorToFloor();
                    willSnapToFloorOnStart = false;
                }
                else
                {
                    if (gravitySettings.usesGravity && !isGravityFrozenForSingleFrame)
                    {
                        ApplyGravity();
                    }
                    else
                    {
                        if (Mathf.Abs(properties.acceleration.x) > 0.0f && Mathf.Abs(properties.velocityCap.x) > 0.0f)
                        {
                            ApplyAccelerationY();
                        }

                        ApplyDecelerationY();
                    }

                    CheckVerticalCollisions((properties.velocity.y + properties.externalVelocity.y) * PhysicsManager.Instance.fixedDeltaTime);

                    if (raycastAmounts.enableDetailedSlopeCollisions)
                    {
                        CheckForSlopesInOtherDirection();
                    }

                    ApplyVerticalVelocity();
                }
            }

            properties.externalVelocity = Vector2.zero;
            singleFrameVelocityAddition = Vector2.zero;

            isXMovementFrozenForSingleFrame = false;
            isYMovementFrozenForSingleFrame = false;
            isGravityFrozenForSingleFrame   = false;
        }
Пример #3
0
 //Plays a sound effect only if the object playing the sound effect is currently within the boundaries of the main camera
 public void PlaySoundIfOnCamera(AudioClip clip, float pitch = 1.0f, AudioSource source = null)
 {
     if (CameraHelper.CameraContainsPoint(transform.position, 1.5f))
     {
         AudioSource newSource = (source == null) ? GetComponent <AudioSource>() : source;
         if (newSource != null)
         {
             newSource.pitch = pitch;
             newSource.PlayOneShot(clip);
         }
     }
 }
Пример #4
0
        protected void GenerateExitSplash(Vector2 location, Transform actor)
        {
            if (exitSplashPool)
            {
                GameObject splash = exitSplashPool.Spawn().gameObject;
                splash.GetComponent <RexParticle>().Play();
                splash.transform.position = new Vector3(location.x, location.y, splash.transform.position.z);
            }

            if (CameraHelper.CameraContainsPoint(actor.position, 1.5f))
            {
                PlaySplashSound();
            }
        }
Пример #5
0
        void Update()
        {
            if (slots.spriteRenderer != null && isFiring)
            {
                slots.spriteRenderer.transform.localEulerAngles = new Vector3(slots.spriteRenderer.transform.localEulerAngles.x, slots.spriteRenderer.transform.localEulerAngles.y, slots.spriteRenderer.transform.localEulerAngles.z + rotationSpeed * slots.physicsObject.properties.velocity.x);
            }

            if (willDestroyWhenOffscreen)
            {
                float buffer = 2.5f;
                if (!CameraHelper.CameraContainsPoint(transform.position, buffer) && !isDead)
                {
                    Clear();
                }
            }
        }