• 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
Question by RkySmart · May 28, 2013 at 12:32 PM · rotateforwardwalkingleftright

Walking forward

I know alot of questions about t$$anonymous$$s already, but not like a I want. I want my character to move only forward and rotate left and right.

I have the script to rotate

 function Update () 
 {
      if(Input.GetKey(KeyCode.LeftArrow))
           {
                transform.Rotate(0f,-5f,0f);
           }
 
 
       if(Input.GetKey(KeyCode.RightArrow))
           {
                transform.Rotate(0f,5f,0f);
           }
 }

Very simple script. I don't know if possible to do somet$$anonymous$$ng like that to walk forward.

 if(Input.GetKey(KeyCode.UpArrow))
      {
 
      }

Thanks for the help :)

Comment

People who like this

0 Show 1
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 Lovrenc · May 28, 2013 at 12:36 PM 0
Share

I dont know what you want.

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by SubatomicHero · May 28, 2013 at 12:48 PM

You need to look into using Time.deltaTime as part of your movement scripts. It helps keep movement smooth.

Moving forward would just be a case of using transform.Translate(....);

Hope t$$anonymous$$s helps.

Comment

People who like this

0 Show 4 · 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 RkySmart · May 28, 2013 at 04:33 PM 0
Share

thanks works like I want, but one question.

I don't know if it is because of that but the player goes through walls.

Any solution please?

avatar image delogan · May 28, 2013 at 04:37 PM 0
Share

You need to add colliders/rigidbody physics components to your objects in order for them to react to each other. You can read further on this topic here: http://docs.unity3d.com/Documentation/Manual/Physics.html

avatar image RkySmart · May 28, 2013 at 05:03 PM 0
Share

I tried a box collider, capsule collider and character controller.

But it stills going through walls (walls also have a box collider)

avatar image delogan · May 28, 2013 at 05:41 PM 0
Share

http://docs.unity3d.com/Documentation/Components/class-Rigidbody.html

avatar image

Answer by ragnaros100 · May 28, 2013 at 12:49 PM

Transform.Translate() should work properly here

Comment

People who like this

0 Show 0 · 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

17 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

Related Questions

Make a cube rotate in right or left direction randomly 3 Answers

Moving Right pressing left 1 Answer

Rotating a cube changes its local forward? 1 Answer

How do you make an object go left and right? 1 Answer

How to turn your object left and right 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