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 /
  • Help Room /
avatar image
0
Question by fantekvelik · Aug 08, 2021 at 01:59 PM · input.getaxissplit-screen

Controlling 2 players using input.getaxis

I am making a game which has 2 players. Its a split-screen game. one player is controller using AWSD and the other using arrow keys. The code for moving the players(Car) is using Horizontal and Vertical Axis. I made 2 separate scripts for the two players. The only difference in the two scripts is that one uses "Horizontal" and "Vertical" while the other uses "horizontal2" and "Vertical2". I've set up the two axis so one uses AWSD and one arrow keys but it doesn't work. If this way of doing it is impossible I would appreciate a suggestion of how to implement this in other way. There isn't any difference between the two except the previously mentioned "horizontal2" and "Vertical2". Here is the code.

 private WheelCollider[] wheels;

 public Rigidbody target;
 public float speed2 = 0.0f;
 public float RoundedSpeed = 0.0f;
 public float carMaxSpeed = 100.0f;
 public float speed3;

 public bool isBraking = false;
 float range = 0;

 public float force = 0;

 public float maxAngle = 30;
 public float maxTorque = 300;
 public GameObject wheelShape;

 public static RearWheelDrive cc;

 // here we find all the WheelColliders down in the hierarchy
 public void speed()
 {
     speed2 = target.velocity.magnitude * 3.6f;

     speed3 = speed2 / 100 + 0.5f;

     RoundedSpeed = Mathf.Round(speed2 * 100.0f) * 0.1f;
 }

 public void Start()
 {
     wheels = GetComponentsInChildren<WheelCollider>();

     cc = this;

     for (int i = 0; i < wheels.Length; ++i) 
     {
         var wheel = wheels [i];

         // create wheel shapes only when needed
         if (wheelShape != null)
         {
             var ws = GameObject.Instantiate (wheelShape);
             ws.transform.parent = wheel.transform;
         }
     }
 }

 public void Update()
 {
     speed();

     float angle = maxAngle * Input.GetAxis("Horizontal");
     float torque = maxTorque * Input.GetAxis("Vertical");


     /* if (!Input.GetKey("w") && Input.GetKey("s"))
     {
         if (RoundedSpeed == 0f && torque == 0)
         {
             torque = 0f;

             if (Input.GetKey("s"))
             {
                 isBraking = true;
                 torque = -200;
             }
         }
         else
         {
             isBraking = false;
         }
     } */

     force = torque;

     foreach (WheelCollider wheel in wheels)
     {
         if (wheel.transform.localPosition.z > 0)
             wheel.steerAngle = angle;

         if (wheel.transform.localPosition.z < 0)
             wheel.motorTorque = torque;

         if (wheel.transform.localPosition.z > 0)
             wheel.motorTorque = torque;

         // update visual wheels if any
         if (wheelShape) 
         {
             Quaternion q;
             Vector3 p;
             wheel.GetWorldPose (out p, out q);

             // assume that the only child of the wheelcollider is the wheel shape
             Transform shapeTransform = wheel.transform.GetChild (0);
             shapeTransform.position = p;
             shapeTransform.rotation = q;
         }

     }
 }
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

0 Replies

· Add your reply
  • Sort: 

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

165 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 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 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 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 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 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 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 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 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 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

8-way movement (diagonal) idle issues 1 Answer

Flipping sprite resets on no input 1 Answer

How to import a Unity VR Project into Android Studio? 0 Answers

UI Image not firing function constantly when held down. 1 Answer

Can't get any value from ReadValue vector 2 (New Input System) 0 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