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 /
  • Help Room /
avatar image
0
Question by Santchoss · Jan 28, 2019 at 04:43 PM · triggercharactercontrollertimespeed

How to change FirstPerson Controller Speed OnTriggerEnter event for a certain amount of time?

Hey there,

So, im a complete noob with Unity, i got some of the basics and im in front of a problem that lies far beyond my curent understanding of using C#.

There's a standard asset FPSController that is tagged as "Player" that i want to freeze when passing through a door ("ZoneArrivee") for 4s to play a music and load NextLvl. By searching ive read that it's better to change the Controller speed in it's script than disabling First Person Controller (Which i tried and didn't worked), and after hours of testing multiple things i come here with the following script attached to my "ZoneArrivee" (which is a cube with a rigid body and triggered box collider) :

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.SceneManagement;
 
 public class ZoneArrivee : MonoBehaviour
 {
     public AudioClip SoundVictory;
     public string LevelToLoad;
     public CharacterController controller;
     void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.tag == "Player")
         {
 
             controller = GetComponent<CharacterController>();
             float moveSpeed = 0f;
             Vector3 relativeForward = transform.TransformDirection(Vector3.forward);
             controller.Move(relativeForward * moveSpeed * Time.deltaTime);
             StartCoroutine("Win");
         }
     }
         IEnumerator Win()
         {
             GetComponent<AudioSource>().PlayOneShot(SoundVictory);
             yield return new WaitForSeconds(4);
             SceneManager.LoadScene(LevelToLoad);
         }
 }

With that, by passing through the door, i got : "There is no 'CharacterController' attached to the "ZoneArrivee" game object, but a script is trying to access it. You probably need to add a CharacterController to the game object "ZoneArrivee". Or your script needs to check if the component is attached before using it. UnityEngine.CharacterController.Move (UnityEngine.Vector3 motion) <0x181cf5f0 + 0x0005a> in :0 ZoneArrivee.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Script/ZoneArrivee.cs:20)"

While my FPS Controller is actually attached to the Controller space in the inspector for "ZoneArrivee". An helpful hand on how to call the speed of the Controller and how the whole thing work would be really appreciated since anything i find isn't really clear on how to do it (my comprehension in cause).

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

197 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 avatar image avatar image

Related Questions

How to make my powerup last for about five seconds then go back to normal? 3 Answers

How to Get Speed to Very Gradually Pick Up Over Time? 2 Answers

Is Something Wrong With My Singleton Pattern? 1 Answer

How can I use "animator.SetTrigger()" if "animator.SetBool()" has been true for X amount of seconds? 0 Answers

I need my timer to only start after it hits a trigger. Please help! 0 Answers


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