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 Thijsx7 · Apr 13, 2016 at 03:53 PM · movementtransformmovement scripttranslate

transform.Translate is too smooth

I am currently working on a top down game and I am almost done with the character movement but I ran into a problem: transform.Translate doesn't stop immediately when I release the movement buttons. Instead, it slowly stops. I don't want this as I am going to add animations to my character and I don't want it to look weird when you want to stop moving. Here is the code I am currently using:

 using UnityEngine;
 using System.Collections;
 
 public class CharacterController : MonoBehaviour {
 
     Rigidbody Ridgidbody;
     public float Speed = 1;
     // Use this for initialization
     void Start () {
         Ridgidbody = GetComponent<Rigidbody>();
     }
     
     // Update is called once per frame
     void Update () {
         float Horizontal = Input.GetAxis("Horizontal");
         float Vertical = Input.GetAxis("Vertical");
         Vector3 Movement = new Vector3(Horizontal, 0, Vertical);
         transform.Translate(Movement * Time.deltaTime * Speed);
         
 
         
     }
 }

I hope anyone knows an answer to my problem.

Greetings

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Rob2309 · Apr 13, 2016 at 04:12 PM

The first thing I would change if you want frame prefect input, is to change Input.GetAxis to Input.GetAxisRaw... This prevents Unity from interpolating the input, which is most likely the reason why your movement does not stop immediately.

Comment
Add comment · Show 1 · 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 Rob2309 · Apr 13, 2016 at 04:13 PM 0
Share

If that does not I help try removing the rigidbody if it isn't necessary...

avatar image
1

Answer by felix11 · Apr 13, 2016 at 04:46 PM

I always like to do these things with the rigidbody: instead of : transform.Translate(Movement Time.deltaTime Speed); try: Rigidbody.velocity = (Movement * Speed);

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

Answer by b1gry4n · Apr 13, 2016 at 04:14 PM

change your speed variable from 1 to something like 5, 10, 15. The higher the number the faster it reaches its target, i guess you could say

Comment
Add comment · Show 1 · 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 Thijsx7 · Apr 13, 2016 at 07:30 PM 0
Share

I set my speed variable in the editor so this was not the case. Still thanks for answering!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Limit movement to just forward/backward and left/right 0 Answers

Rigidbody2D.MovePosition() doesn't do anything (but animations and transform.Translate() works) 0 Answers

Limit movement to just forward/backward and left/right 0 Answers

2D Using C# moving game object back and forth and random stop in between - all in x-axis 2 Answers

Diagonal character movement 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