Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 stuntrunt · Sep 11, 2013 at 10:49 PM · rotationmovementcontroller

Player Controller Rotation Script Help

Hello, I'm in the early stages of a game design. It's between a third person and top down shooter. I'm not the programming type, more of a designer, so I need help making a script. At the moment, all I have is a cube and the ground. I have a script that moves the character, but not quite how I would like it. There is also no gravity. I need a script that, when pressing "w" or "s" the cube moves back and forth and when I press "a" or "d" , I want the cube to rotate rather than moving like "w" and "s" movements. I also have the camera under the player cube in the hierarchy so the camera moves with the cube

Comment
Add comment · Show 4
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 ShadoX · Sep 11, 2013 at 11:10 PM 0
Share

Sorry for the lack of code, but this seems to be a rather simple question that would be answered by checking out some tutorials. Anyway you should be able to get this done by using the following things:

1) http://docs.unity3d.com/Documentation/ScriptReference/Input.Get$$anonymous$$eyDown.html

2) http://docs.unity3d.com/Documentation/ScriptReference/Transform.Translate.html

3) http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html

There are other ways of doing it, but this should get your cube moving. :)

avatar image stuntrunt · Sep 11, 2013 at 11:45 PM 0
Share

These references has helped a ton, ShadoX. And for that I am very thankful. I have gotten it working, however it only moves 1 unit/second, and I have to mash the keys for it to move more. How can I make it so I can hold the key and change how much is moved?

avatar image ShadoX · Sep 12, 2013 at 08:09 AM 0
Share

Sorry, forgot about that. You probably want to multiply the value with Time.deltaTime http://docs.unity3d.com/Documentation/ScriptReference/Time-deltaTime.html

avatar image stuntrunt · Sep 12, 2013 at 09:06 PM 0
Share

Here is my code I am using to move my cube. I have tried multiplying the Time.deltatime but I cannot seem to get it to work. It is a Javascript code as well. I tried adding a variable like the link you gave me, but does the same thing. Not sure where to go from here. Thanks ShadoX

 function Update()
 
     {
     
             //$$anonymous$$oves Player Foward 1 unit/second
                 if(Input.Get$$anonymous$$eyDown("w"))
                 transform.Translate(Vector3.forward * Time.deltaTime);
             
             //$$anonymous$$oves Player Back 1 unit/second
                 if(Input.Get$$anonymous$$eyDown("s"))
                 transform.Translate(Vector3.back * Time.deltaTime);
             
             //Rotates Plater Right 1 unit/second
                 if(Input.Get$$anonymous$$eyDown("d"))
                 transform.Rotate(Vector3.up * Time.deltaTime);
             
             //Rotates Plater Left 1 unit/second
                 if(Input.Get$$anonymous$$eyDown("a"))
                 transform.Rotate(Vector3.down * Time.deltaTime);
             
     }

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by save · Sep 11, 2013 at 11:05 PM

What I always say is that you need to break apart the problem, what you basically need is input which controls movement and rotation. First of all, these are, not to anyones surprise, the most asked questions - so searching for them would serve you a fair amount of results. Unity also have a lot of sweet examples in their scripting reference, for instance - the GetAxis in the Input class shows you exactly what you want to achieve.

I would like to further refer you to the community part where you could find programmers to team up with. If you want to get deeper into scripting the scripting reference and scripting section in the manual is a great place to start.

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
0

Answer by stuntrunt · Sep 13, 2013 at 02:45 AM

Here is my revised code I have working now. However, how can I make it so that my mouse cursor does the same, or replaces the left and right arrow keys that controls rotation? This will be implemented into Android once I have a working beta up so the movements will be controlled via touch, but I'll cross that bridge when I come to it. Also, how do you add gravity without using the RigidBody, or use the RigidBody but smooth it out so it isn't so jerky.

 function Update()

 
     {
                 var walkSpeed: float = 10;
                 var rotateSpeed: float = 175;
                 var jumpHeight: float = 50;
                 var runSpeedMultiplyer: float = 1.5;
                 
             //Moves Player Foward
                 if(Input.GetKey("w"))
                 transform.Translate(Vector3.forward * Time.deltaTime * walkSpeed);
             
             //Moves Player Back
                 if(Input.GetKey("s"))
                 transform.Translate(Vector3.back * Time.deltaTime * walkSpeed);
             
             //Moves Player Right
                 if(Input.GetKey("d"))
                 transform.Translate(Vector3.right * Time.deltaTime * walkSpeed);
                 
             //Moves Player Left
                 if(Input.GetKey("a"))
                 transform.Translate(Vector3.left * Time.deltaTime * walkSpeed);
             
             //Rotates Player Right
                 if(Input.GetKey("right"))
                 transform.Rotate(Vector3.up * Time.deltaTime * rotateSpeed);
             
             //Rotates Plater Left
                 if(Input.GetKey("left"))
                 transform.Rotate(Vector3.down * Time.deltaTime * rotateSpeed);
                 
             //Player Jumps
                 if(Input.GetKeyDown("space"))
                 transform.Translate(Vector3.up * Time.deltaTime * jumpHeight);
                 
             //Player Runs
                 if(Input.GetKey("up"))
                 transform.Translate(Vector3.forward * Time.deltaTime * walkSpeed * runSpeedMultiplyer);
                 
             
         
     }
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.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Multiple Cars not working 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Joystick for WASD & Joystick for Camera? 0 Answers

BCE0044: Expecting : Found = Error! 2 Answers

Help with fps script 2 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