• 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 Dakkyyy · Mar 17, 2021 at 07:58 PM · unityeditor

How do I make speed decrease after death?

Ok, so I’m making a game that as you run your speed increases, if you aren’t running it decreases. I’ve noticed after the player's death, which is really just teleporting back to the start, the player will maintain the same speed. How would I make the speed reset back to normal after the death? Idk how to show the code on here as a lot of ppl do so if you know how to fix it but need to see my code. Plz tell me how to show the code lol

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by tdx110 · Mar 17, 2021 at 09:00 PM

I propose to write the speed at the beginning to a static variable that does not disappear, and set it after teleporting. This is code (If your speed is not 0)

     static float variable = 0;
     void Update()
     {
         if(variable ==0) vatiable = /*Your speed*/
                 else /*Your speed*/ = variable
     }
Comment
Add comment · Show 3 · 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 Dakkyyy · Mar 18, 2021 at 12:07 AM 0
Share

How did you make the code box? I want to post what I have and I’d like to see if there’s a way to fix what I have because I’m pretty new to all this so idk if I’m just doing it right but wording it wrong. I’ve already fixed a few things like that but idk how do it on this problem I’m having

avatar image Dakkyyy · Mar 18, 2021 at 12:18 AM 0
Share
 {
    [SerializeField]private Transform player;
    [SerializeField]private Transform respawnPoint;
  
     private float Death;
     private float speed;
 
     // Start is called before the first frame update
     void Start()
     {
        player.transform.position = respawnPoint.transform.position;
 
        Death = (player.transform.position = respawnPoint.transform.position);
     }
 
     // Update is called once per frame
     void Update()
     {
         if (Death)
         {
             speed = 400;
         }
     }
 }

avatar image tdx110 Dakkyyy · Mar 18, 2021 at 09:34 AM 0
Share

Try this:

     private float speed;
     private float startSpeed;
     //True when must go to respawn point
     private bool isDeath = false;
 
     private void OnEnable()
     {
         player.transform.position = respawnPoint.transform.position;
         speed = 400;
         startSpeed = speed;
     }
     void Update()
     {
         if (isDeath)
         {
             player.SetActive(false);
             player.transform.position = respawnPoint.transform.position;
             player.SetActive(true);
             speed = startSpeed;
         }
     }

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

117 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

Related Questions

Unity Editor Self Signed Certificates Error on launch 2018.1.5f1 0 Answers

ML-Agent imitation training get slower and slower as it progresses 0 Answers

Reduce APK file Size with Vuforia 0 Answers

unity showing download file delay 0 Answers

How to compare velocity of joint between 2 model in Unity ? 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