controller input question
I have a game were a cube is constantly moving forward and you have to move it out the way of obstacles I changed over the input system to gamepad without any issues but when I implement a new movement script it doesn't work as it should. I would like it as when you move the analogue stick the cube moves with it but if I move the stick the cube moves once instead of continuously I'm a bit confused please help me. here is code and screenshot:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem;
public class Playerscript : MonoBehaviour { public Rigidbody rb; public float forwardForce =2000f; public float sidewaysForce = 500f; PlayerControls controls; void FixedUpdate() { rb.AddForce(0, 0, forwardForce * Time.deltaTime); if (rb.position.y < -1f) { FindObjectOfType().EndGame();
}
}
void Awake() { controls = new PlayerControls(); controls.Gameplay.Game1.performed += ctx => Game1(); controls.Gameplay.Game2.performed += ctx => Game2();
}
void Game1() { rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
void Game2() { rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); } void OnEnable() { controls.Gameplay.Enable();
} void OnDisable() { controls.Gameplay.Disable(); } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613045618im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GXDKGamepad - the motors wont stop after calling SetMotorSpeeds(0,0,0,0) 0 Answers
Does Unity WebGL support Xbox One controllers? (as of 5.4.0f3) 1 Answer
Move an object around all 6 sides of a cube 2 Answers
Can I access a headset that is connected with the Xbox One gamepad? 0 Answers
Why Does My Cube Player rotate 180 degrees when I start My game? 2 Answers