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 Lordships · Apr 21, 2011 at 09:49 PM · movementcharacterrotate

Two Keys ws or wd detection

I am working on a birds eye view game in which the player uses wasd to move about. However I am running into an issue with this. For example when the player presses w the character moves forward, and when the player presses a or d the character rotates left or right. I would like to have it so so when the player presses aw at the same time It would rotate/move simultaneously.

Current Key Detection:

function OnGUI () { //Set up hotkey "w" for Forward if (Event.current.Equals (Event.KeyboardEvent ("w"))) ThurstersForward();

 //Set up hotkey "w" for Forward
 if (Event.current.Equals (Event.KeyboardEvent ("s")))
 ThurstersBackward();

 //Set up hotkey "d" for rotate right
 if (Event.current.Equals (Event.KeyboardEvent ("d")))
 rotateRight();

 //Set up hotkey "a" for rotate right
 if (Event.current.Equals (Event.KeyboardEvent ("a")))
 rotateLeft();

}

Current Resulting Action:

function ThurstersForward(){ rigidbody.AddForce(transform.forward); transform.Find("ThrusterA").GetComponent("EllipsoidParticleEmitter").enabled = true; transform.Find("ThrusterB").GetComponent("EllipsoidParticleEmitter").enabled = true; }

function ThurstersOff(){ transform.Find("ThrusterA").GetComponent("EllipsoidParticleEmitter").enabled = false; transform.Find("ThrusterB").GetComponent("EllipsoidParticleEmitter").enabled = false;
}

function ThurstersBackward(){ rigidbody.AddForce(transform.forward * -2); }

function rotateRight(){ Debug.Log(transform.rotation); transform.Rotate(Vector3.up * 2); }

function rotateLeft(){ transform.Rotate(Vector3.up * -2); }

Any Suggestions, Right now only one can be "active" at a time. I looked into using threads but it appeared that unity did not support them.

Comment
Add comment · 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 AngryOldMan · Apr 25, 2011 at 01:33 PM 0
Share

check update changed per comment

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by AngryOldMan · Apr 21, 2011 at 10:19 PM

you could use/edit the keys thats unity have set in the input manager. Instead of setting up hot keys? And use Input.GetAxis in the fixed update function rather than each key firing off a seperate function

EDIT

if that doesnt work then something like

function FixedUpdate ()
{
    if (Input.GetKey ("w"))
    {
        rigidbody.AddForce(transform.forward);
            //stuff about your particle emitter here
    }
    if (Input.GetKey ("a"))
    {
        transform.Rotate(Vector3.up * -2);
    }
    //etc for the rest of your inputs
}
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 Lordships · Apr 25, 2011 at 03:37 AM 0
Share

This doesn't seem to work unless I continuously tap the keys which is not quite what I am looking for.

avatar image
0

Answer by burgunfaust · Apr 21, 2011 at 10:30 PM

You could just use "q" and "e" for forward left and forward right:

//Set up hotkey "q" for ForwardLeft if (Event.current.Equals (Event.KeyboardEvent ("q"))) { ThurstersForward(); rotateLeft(); }

//Set up hotkey "e" for ForwardLeft if (Event.current.Equals (Event.KeyboardEvent ("e"))) { ThurstersForward(); rotateRight(); }

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 Lordships · Apr 25, 2011 at 04:15 AM

I found this works great!

var rotateSpeed = .50; var thrustSpeed = 5.0;

function FixedUpdate(){ .......

 transform.Rotate (Vector3.up * (Input.GetAxis("Horizontal") * rotateSpeed * Time.deltaTime) ); 

 if (Input.GetButton("Vertical") ) { 
   rigidbody.AddRelativeForce (Vector3.forward * thrustSpeed * Time.deltaTime); 
 }

}

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

No one has followed this question yet.

Related Questions

Rotate Character with movement 3 Answers

How can I stop player snapping back to 0,0,0 rotation when I release keys? 1 Answer

Character Rotate Properly 2 Answers

Character controller + animation of different meshes making one character 1 Answer

about character movement in 8 direction 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