Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Code1345 · May 25, 2018 at 11:35 PM · camerascripting problem

Trying to freeze FPS character to one point for a specific amount of time

Hello! So, I have a problem that has been driving me crazy. I am trying to create a simple scene where the player enters a dungeon, and is frozen in place looking at the enemy speak for about five seconds. Afterwards, the player would be unlocked from any restraints. I have tried using the freeze rigidbody method, but the player would just run in place. The script I have is also on the FPS controller, and it has a sword and shield attached, so I can't disable it.Using this script here will partially freeze the player, letting them sprint and walk in place. Also, when the five seconds is up, the camera will jerk wildly for a few seconds before going off to the right, and everything returns to normal. Any help would be greatly appreciated! using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityStandardAssets.Characters.FirstPerson;

 public class FPSplacement : MonoBehaviour {
      
     private GUIruntime2 guiruntime2;
     public GameObject FPSController;
     public Transform target;  
     public GameObject spawn;
     // Use this for initialization
     void Start () {
         Scene currentscene = SceneManager.GetActiveScene();
         string sceneName = currentscene.name;
         guiruntime2 = FPSController.GetComponent<GUIruntime2>();
  
  
  
  
     }
    
     // Update is called once per frame
     void Update () {
  
         if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("SimpleSword2part2") && guiruntime2.roar == true)
         {
             StartCoroutine(Waiting());
            
         }
     }
     IEnumerator Waiting()
     {
        
      transform.position = spawn.transform.position;
         //transform.LookAt(target); is to make the player look at the NPC.
         transform.LookAt(target);
         //target is the enemy
         yield return new WaitForSeconds(5);
         //To make the character look at the NPC after the timer.
         transform.LookAt(target);
         //guiruntime2 is the dialouge that the NPC has on screen. After five seconds it becomes disabled.
         //when guiruntime is finished, it has a bool that is set to false.
         guiruntime2.roar = false;
      
  
  
  
  
     }
 }
  
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Aggrojag · May 25, 2018 at 11:48 PM 0
Share

I mainly develop 2D, and write my own controllers. Had to take a quick peak at how the FPSCC works. It looks like you still read inputs, then dictate what the controller should do. For a precise answer, I imagine it'd be best if you also included your animation code, and any code that accepts input and acts upon it (moving your player, moving your camera, firing/using a weapon).

For a less precise answer, having a boolean value that prohibits the reading of input will get you a long way.

 Player.instance.CanControl(false);

From what I can tell, it looks like you're actively trying to counteract other behaviors, rather than just stopping them from acting.

avatar image Code1345 Aggrojag · May 26, 2018 at 02:17 PM 0
Share

I ended up doing something like that, and just disabling the FPS script. I am sorry that it wasn't super clear, that was something I was afraid of. Thank you for your response, I really do appreciate it- and I'll have to keep your solution in $$anonymous$$d in case I need it later on :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by browne11 · May 25, 2018 at 11:52 PM

Your coroutine appears to be running in the update sequence which isn't a great idea. However you can still make it work but you need to use another variable inside the update function preventing it from getting called more then once; which appears to be the issue.

This isn't the most elegant way of doing it but it will solve your issue of the coroutine getting activated multiple times.

 public class FPSplacement : MonoBehaviour {
     private bool freeze;
     private GUIruntime2 guiruntime2;
     public GameObject FPSController;
     public Transform target;  
     public GameObject spawn;
     // Use this for initialization
     void Start () {
         Scene currentscene = SceneManager.GetActiveScene();
         string sceneName = currentscene.name;
         guiruntime2 = FPSController.GetComponent<GUIruntime2>();
 
 
 
 
     }
 
     // Update is called once per frame
     void Update () {
 
         if (SceneManager.GetActiveScene () == SceneManager.GetSceneByName ("SimpleSword2part2") && guiruntime2.roar == true) {
             if (freeze != true)
             {
                 StartCoroutine (Waiting ());
             }
 
         }
     }
     IEnumerator Waiting()
     {
         freeze = true;
         transform.position = spawn.transform.position;
         //transform.LookAt(target); is to make the player look at the NPC.
         transform.LookAt(target);
         //target is the enemy
         yield return new WaitForSeconds(5);
         //To make the character look at the NPC after the timer.
         transform.LookAt(target);
         //guiruntime2 is the dialouge that the NPC has on screen. After five seconds it becomes disabled.
         //when guiruntime is finished, it has a bool that is set to false.
         guiruntime2.roar = false;
         freeze = false;
 
 
 
 
 
     }
 }


Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Code1345 · May 26, 2018 at 02:16 PM 0
Share

Thank you for the reply! I tried your script, but it didn't work for me. Thank you for providing it though, I really do appreciate it. But I don't think the issue is the coroutine being called more than once- I have a condition that says that guitime2.roar has to be equal to true before the coroutine actually runs, and at the end of the coroutine it sets it to false. But, I managed to remedy the problem by just disabling the FPS controller script. Thank you again though for your answer!

avatar image browne11 Code1345 · May 27, 2018 at 12:44 AM 0
Share

If you look closely, the roar is set to true it then enters the update sequence and starts the coroutine which takes 5 seconds before you finally turn it to false. So technically you can still start a new coroutine during the 5 seconds it takes to turn it off.

The update is run every .02 seconds give or take the speed of your computer so you're starting a new coroutine on top of the already running ones. I would guess you have close to 250 of them running.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

195 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The referenced script (CameraContoller) on this Behaviour is missing! 1 Answer

How to make character head face in the direction of where the mouse is pointing in FreeFormCameraRig? 0 Answers

[ C#] Character Movement based on Camera Direction. 2 Answers

How to change post-processing behaviour of a camera through script? 2 Answers

How to detect an object which be in FOV of certain camera ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges