Question by
maxfield1 · Aug 22, 2016 at 10:52 PM ·
charactercontrollercharacter controller
How do i make my 2D character jump by touching the screen?
I have a code that lets the character jump with the spacebar but I would like it to jump with a touch of the screen.
Comment
Answer by darchyneer · Sep 22, 2017 at 06:39 AM
There are many ways to do this. You can start by adding a rigidbody and capsule collider to your gameobject. (provided you use C# for coding)The coding could go like this:`private Rigidbody rb; `pubic float jumpSpeed = 10.0f; void Start () {
rb = GetComponent<Rigidbody>();
}
if(Input.GetKeyDown(KeyCode.Space)){
rb.AddForce(transform.up * jumpSpeed);
}
Your answer
Follow this Question
Related Questions
Boat Controller Help 0 Answers
Help with exception to DontDestroyOnLoad 2 Answers
Character Controller keeps going even if I limit it 1 Answer
Hinge joint limits not working properly 1 Answer
CharacterController getting stuck on slope corners 0 Answers