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 ProXenT · Dec 01, 2012 at 09:04 PM · movement

Need a help for movement Script!

Hi everybody, i'm making a game with 2 player on PC, and i need to configure the movement like that : Player 1 play with the "WASD keys" and player 2 with "Arrow keys (left,right,up,down)".. but i don't know how to do my script, Vector3 or 2 ? i need help plz.. if possible give me an example of what i need to do plz..

P.S: My game is not in 1 person, it's like a PacMan Style. Thanks.!

Comment
Add comment · Show 2
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 ProXenT · Dec 01, 2012 at 10:38 PM 0
Share

Plz anyone ?

avatar image azmat786n · Dec 01, 2012 at 11:03 PM 0
Share

wait........

1 Reply

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

Answer by azmat786n · Dec 01, 2012 at 11:21 PM

 //player one script
 var moveSpeed:float = 10.0f;
     
 function Update() {
     if(Input.GetAxis("Horizontal")||Input.GetAxis("Vertical")) 
  {
   transform.Translate(Input.GetAxis("Horizontal") * moveSpeed,Input.GetAxis("Vertical")* moveSpeed,0)
  }
 }


player 2

     //player2 script
     var moveDir:Vector3 = Vector3.zero;
     function Update() {
     
         //move left
         if (Input.GetKey(KeyCode.A))
         {
             moveDir.x = -5;
         }
         //move right
         else if (Input.GetKey(KeyCode.D))
         {
             moveDir.x = 5;
         }
         //move down side
         else if (Input.GetKey(KeyCode.S))
         {
             moveDir.y = -5;
         }
         //move up side
         else if (Input.GetKey(KeyCode.W))
         {
             moveDir.y = 5;
         }
         else
         {
             //if not pressed any key
             moveDir.x = 0;
         }
         
         //start movement
         transform.Translate(dir  * Time.smoothDeltaTime);
     }



i hope this is helpful

Comment
Add comment · Show 10 · 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 ProXenT · Dec 02, 2012 at 03:34 AM 0
Share

Thankss !! :)

avatar image ProXenT · Dec 02, 2012 at 03:43 AM 0
Share

But, i have test your script and the playerone, pass into all my wall, and move very fast.. and the player 1 and 2 does not go foward and backward, they go up and down trought my floor.

avatar image ProXenT · Dec 02, 2012 at 02:17 PM 0
Share

hes going in the sky and trought my floor.

avatar image lucax · Dec 02, 2012 at 02:20 PM 0
Share

decrease the movespeed float and do your walls have collider ?

avatar image ProXenT · Dec 02, 2012 at 02:26 PM 0
Share

yes i have it, but i found the problem with the Y axes..

Show more comments

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

12 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

Related Questions

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

Set up a 3D fly through 4 Answers

TERA style movement 1 Answer

Simulating Marble Blast Gold: A script to make a character as a marble roll forward, mouse turns screen? 2 Answers

Move object towards mouse in full 3D space 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