Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 latsushi · Nov 17, 2012 at 07:44 PM · c#accelerationslow downmodulus

Slow down acceleration

Hello Unity Community,

I have a script that has an object accelerate but my problem is that it accelerates to fast. How can I slow down the acceleration? I figured I could do something with the modulus operator but I can't seem to figure it out. Here's my code:

 using UnityEngine;
 using System.Collections;
 
 public class MoveForward : MonoBehaviour {
     public float speed = 6.0F;
     public float jumpSpeed = 8.0F;
     public float gravity = 20.0F;
     private Vector3 moveDirection = Vector3.zero;
     public int i;
     public int MaxSpeed = 500;
     public int MinSpeed = 5;
     
     
     // Update is called once per frame
     void FixedUpdate () {
         CharacterController controller = GetComponent<CharacterController>();
          if (controller.isGrounded) {
             moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), (2*i)/100);
             moveDirection = transform.TransformDirection(moveDirection);
             moveDirection *= speed;
              if (Input.GetButton("Jump"))
                 moveDirection.y = jumpSpeed;
             if (i < MaxSpeed){
                 i++;
                 print (i);
                     
             }
                     
             
         }
         moveDirection.y -= gravity * Time.deltaTime;
         controller.Move(moveDirection * Time.deltaTime);    
     }
 
 }

The i variable is what's making the object accelerate. The i with the if statement is where I need to put my code for slowing down acceleration. Any help by you fine folks is appreciated. :-)

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
0

Answer by lil_billy · Nov 17, 2012 at 08:33 PM

um no its not i is doing nothing the only thing affecting your speed / acceleration is

speed

which you can change

now I dont know what the physics looks like on your side but if you say it is accelerating then you can just change speed

if it isnt accelerating I recommend looking into MathF.Lerp and lerping the speed

edit: maybe I should explain the script to you

charactercontroller.move is what makes your character move movedirection is the math data that is passed to it to move it by whatever you want as far as i can see i never influences movedirection or any of the variables that influence moveDirection

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 latsushi · Nov 18, 2012 at 05:39 AM 0
Share

Did you miss this line?: moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), (2*i)/100);

I've experimented with this script and when I take out the variable i altogether the object stops accelerating and ins$$anonymous$$d the object moves at a constant speed. So, i is affecting acceleration. I'll look into $$anonymous$$athF.Lerp. Does anyone have any other suggestions?

avatar image lil_billy · Nov 18, 2012 at 06:03 PM 0
Share

yes i did miss that bit, it was hidden by the scroll bar

so how about this i+=.5 or .25

and with deceleration -=.25

and change i to a float :D

oh and you dont want to run all of this in fixed update ins$$anonymous$$d try to do all of this in update and if and only if it jitters then put the final move task into fixed update

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

10 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

Related Questions

rigidbody acceleration 4 Answers

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

Accelerating smoothly to a given level 1 Answer

Input.gyro.gravity and Input.acceleration can't support wp8. 1 Answer

How to speed up deceleration? 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