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 titaniumammas · May 11, 2020 at 07:51 AM · accelerationemission

How to increase the acceleration of the object and affect an emission materials brightness based on it

Hello all; I am creating a game like cubefield and tron legacy and I have came across a bump in the road. I dont know how to add acceleration to this movement script. Let alone correlate that with the emission output of a material. What I am trying to do is if the w key is pressed it will accelerate to a certain max speed and if it is let go it will slowly de-accelerate. I want the emission material to increase its brightness based on the objects speed and decrease also based on its speed. I just need help with those 2 things. Here is my movement script:

  [Tooltip("How fast the character should move with no input, in world units per second")]
     public float autoMoveSpeed = 40.0f;
     [Tooltip("The direction the character should move with no input")]
     public Vector3 autoMoveDirection = Vector3.right;
     // Enforce that this is always a unit direction vector, so it doesn't bias our speed.
     void OnValidate() { autoMoveDirection = autoMoveDirection.normalized; }
 
     [Tooltip("How much the player can affect the speed in the direction of auto movement")]
     public float parallelMoveSpeed = 50f;
     [Tooltip("How fast the player can affect the speed perpendicular to the auto movement")]
     public float perpendicularMoveSpeed = 70f;
 
     [Tooltip("How many points to earn per second with no input")]
     public float scorePerSecondAtDefaultSpeed = 10f;
     [Tooltip("How many extra points to earn per second for every extra unit of speed")]
     public float extraScorePerVelocityUnit = 1.0f;
 
     // Track how much "loose change" points we've accumulated.
     float _scoreAccumulator = 0f;
 
     void Update()
     {
         // Capture the player's input vector.
         Vector3 input = new Vector3(
                             Input.GetAxis("Horizontal"),
                             0,
                             Input.GetAxis("Vertical")
                         );
 
         // Clamp the input to make sure we don't move faster on diagonals.
         input = Vector3.ClampMagnitude(input, 1.0f);
 
         // Extract the portion of the player's input parallel to the auto movement.
         float parallelComponent = Vector3.Dot(autoMoveDirection, input);
 
         // Leaving the component perpendicular to the auto movement.
         Vector3 perpendicularComponent = (input - parallelComponent * autoMoveDirection);
 
         // Compute how much to increase or decrease our auto movement based on our input.
         float extraVelocity = parallelComponent * parallelMoveSpeed;
 
 
         // Compute our net velocity, combining auto, parallel, and perpendicular movement.
         Vector3 velocity = autoMoveDirection * (autoMoveSpeed + extraVelocity)
                          + perpendicularComponent * perpendicularMoveSpeed;
 
 
         // Translate us according to that velocity and the elapsed time.
         transform.Translate(velocity * Time.deltaTime, Space.Self);
 
         // Scoring:
         // Compute our increased (or reduced) scoring rate based on our forward velocity.
         float extraScore = extraVelocity * extraScorePerVelocityUnit;
 
         // Increase our score accumulator based on our current earning rate and time passed.
         _scoreAccumulator += (scorePerSecondAtDefaultSpeed + extraScore) * Time.deltaTime;
 
         // Whenever we earn a whole point, send it to the score display as an integer.
         int scoreUnits = Mathf.FloorToInt(_scoreAccumulator);
         scorecript.scoreValue += scoreUnits;
         // And decrement our accumulator to store just the "spare change".
         _scoreAccumulator -= scoreUnits;
     }
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

124 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

Related Questions

rigidbody acceleration 4 Answers

C# Move object by tilting on android device. 5 Answers

Multitouch: Second touch interferes with the first. 1 Answer

Car acceleration using Xbox 360 triggers? 1 Answer

acceleration setting 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