Note that there are some explanatory texts on larger screens.

plurals
  1. POUse Joysticks in C# to control objects
    primarykey
    data
    text
    <p>Right now Im using the WASD keys to control an object. Now I want to use joysticks to do the same. Can anyone show me how to adapt my code to do this? All I want to do is replace the if (Input.getKey)spaces with a an if (Input) space that will use the joysticks to move the boat left and right.</p> <pre><code>void drive() { //decrease speed if (Input.GetKeyDown(KeyCode.S)) { //in Drive if (acceleration &gt; 0 &amp;&amp; bucketMode == false) { acceleration-= 250; } //in Reverse else if (acceleration &lt; 0 &amp;&amp; bucketMode == true) { acceleration += 250; } } //Increases Speed if (Input.GetKeyDown(KeyCode.W)) { //in Drive if (acceleration &lt; maxSpeed &amp;&amp; bucketMode == false) { acceleration+= 250; } //in Reverse else if (acceleration &gt; minSpeed &amp;&amp; bucketMode == true) { acceleration -= 250; } } //stops the boat and toggles Bucket mode if (Input.GetKeyDown(KeyCode.Space)) { acceleration = 0; if (bucketMode == false) { //goes into revers bucketMode = true; craft.bucket(1); //sends bucket as true } else { //goes into drive bucketMode = false; craft.bucket(0); //sends bucket as false } } //moves forward if speed is + if (acceleration &lt; 0) { //moves backwards at half the speed than in drive, in a smooth motion, speed depending on user input(acceleration) this.transform.Translate(Vector3.left * Time.smoothDeltaTime * ((-acceleration / 500) +1)); //updates craft speed being displayed craft.ChangeSpeed((acceleration/500) * 1.94); } //moves backward if speed is - else if (acceleration &gt; 0) { //moves forward in a smoothb motion, speed depending on user input(acceleration) this.transform.Translate(Vector3.right * Time.smoothDeltaTime * ((acceleration / 250) + 1)); //updates craft speed being displayed craft.ChangeSpeed((acceleration/250) * 1.94); } //stands still if speed is 0 else { } //turns right if (Input.GetKey(KeyCode.D)) { //turns the boat to the left smoothly, as speed increases, so does turn angle this.transform.Rotate(Vector3.forward * Time.smoothDeltaTime * 25 /* ((2 * acceleration / 250) +1)*/); //updates boat information(heading and speed) craft.ChangeHeading(1 * Time.smoothDeltaTime * 25 /* ((2 * acceleration / 250) +1)*/); craft.ChangeSpeed((acceleration/250) * 1.94); //if boat is not moving forwards, moves forward slowly, so boat doesn't turn in place if (acceleration == 0) { this.transform.Translate(Vector3.right * Time.smoothDeltaTime / 2); } } //turns left if (Input.GetKey(KeyCode.A)) { //turns the boat to the right smoothly, as speed increases, so does turn angle this.transform.Rotate(Vector3.back * Time.smoothDeltaTime * 25 /* ((2 * acceleration / 250) +1)*/); //updates boat information(heading and speed) craft.ChangeHeading(-1 * Time.smoothDeltaTime * 25 /* ((2 * acceleration / 250) +1)*/); craft.ChangeSpeed((acceleration/250) * 1.94); //if boat is not moving forwards, moves forward slowly, so boat doesn't turn in place if (acceleration == 0) { this.transform.Translate(Vector3.right * Time.smoothDeltaTime / 2); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload