• 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 McMutton · Nov 10, 2010 at 03:54 PM · moveforward

Transform.Translate not working

Hey there.

I'm trying to set it up so that, when I press Shift, the character plays a certain animation and dashes forward a bit (Forward being to the right or left, depending on which direction you were facing). I assume that you would use transform.Translate for that, but it's not doing anything. The code is as follows:

var tackleSound : AudioClip;

function Update () {

 var isDoor : GateOpen = GetComponent(GateOpen); 


     if (Input.GetButtonDown ("Action")) {
         animation.Play ("shouldertackle");
         transform.Translate(Vector3(5, 0, 0) * Time.deltaTime);
         audio.PlayOneShot(tackleSound);
         }

}

I've also tried most of the code snippets from the website's scripting reference, none of which have worked either. What's with this?

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

2 Replies

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

Answer by Bampf · Nov 10, 2010 at 05:16 PM

deltaTime is a tiny, sub-second value unless your framerate is really bad. Translate is probably working but it isn't moving the character very far. (You could test this by moving it a larger amount.)

Instead, you probably want to move a longer distance, gradually over time. A useful function for that is Lerp, and it's explained very well here: http://answers.unity3d.com/questions/6949/can-someone-explain-how-using-time-deltatime-as-t-in-a-lerp-actually-works/6950#6950

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 McMutton · Nov 11, 2010 at 03:22 AM 0
Share

Ah, I see. But, using that, how would I make it so that the start position is where the character is currently, and the end position is a certain amount of units from that position?

avatar image Bampf · Nov 12, 2010 at 03:02 AM 0
Share

See the $$anonymous$$oveObject function in the example. It takes two vectors. The start position you'd use would be the current position: "transform.position". The end position could be "transform.position + Vector3(5, 0, 0)".

avatar image
0

Answer by Eric5h5 · Nov 10, 2010 at 03:57 PM

GetButtonDown only runs once when the button is first pressed.

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

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

No one has followed this question yet.

Related Questions

How would I make it so that my character moves only so fast 1 Answer

rigidbody.AddForce(transform.forward * 5000) 1 Answer

How to lerp back and forth? (ex. platform) 2 Answers

move box forward 1 Answer

move character controller forward using gui button. 1 Answer


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