Forum rules - please read before posting.

Using VR Fingers for Menus, but game Pauses Physics

I have a big problem, when the AC pauses the game, it also pauses the physics, but since my VR Touch Input uses Physics I cannot use it while in pause. Is there a good way to restart the physics or have to prevent the Adventure Creatore from stoping the physics?

Comments

  • AC's pause mode is handled by zero-ing Unity's TimeScale, so physics will always stop during this time.

    Know that pausing is optional - it's determined by a Menu's Pause game when enabled? property. It's not strictly necessary if you don't want it to be - and you can use the Engine: Manage systems Action to disable e.g. interaction and movement systems while they're enabled to prevent regular gameplay.

    But to "restart" the physics, you could try attaching a script to your Rigidbodys to record their speed when the game pauses - and re-apply this speed when the game resumes.

    Adapted from this post, and making use of AC's OnEnterGameState and OnExitGameState custom events:

    using UnityEngine;
    using AC;
    
    public class PhysicsResume : MonoBehaviour
    {
    
        private Vector3 savedVelocity;
        private Vector3 savedAngularVelocity;
        private Rigidbody _rigidbody;
    
        private void OnEnable ()
        {
            _rigidbody = GetComponent <Rigidbody>();
    
            EventManager.OnEnterGameState += OnEnterGameState;
            EventManager.OnExitGameState += OnExitGameState;
        }
    
        private void OnDisable ()
        {
            EventManager.OnEnterGameState -= OnEnterGameState;
            EventManager.OnExitGameState -= OnExitGameState;
        }
    
        private void OnEnterGameState (GameState gameState)
        {
            if (gameState == GameState.Paused)
            {
                OnPauseGame ();
            }
        }
    
        private void OnExitGameState (GameState gameState)
        {
            if (gameState == GameState.Paused)
            {
                OnResumeGame ();
            }
        }
    
        private void OnPauseGame ()
        {
             savedVelocity = _rigidbody.velocity;
             savedAngularVelocity = _rigidbody.angularVelocity;
             _rigidbody.isKinematic = true;
        }
    
        private void OnResumeGame ()
        {
            _rigidbody.isKinematic = false;
            _rigidbody.AddForce (savedVelocity, ForceMode.VelocityChange);
            _rigidbody.AddTorque (savedAngularVelocity, ForceMode.VelocityChange);
        }
    
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.