How do I make the player rotate left and right with the A and D keys?
What I would like to do is to make the player rotate left when A is pressed and right when D is pressed. In the past when I try this, it also alters the W and D key(which I have just fixed.
This is my current code for the player:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Move2D : MonoBehaviour { public float moveSpeed = 5f; public bool isGrounded = false; // Start is called before the first frame update void Start() {
}
// Update is called once per frame
void Update()
{
Jump();
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
transform.position += movement * Time.deltaTime * moveSpeed;
}
void Jump()
{
if(Input.GetButtonDown("Jump") && isGrounded == true){
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
}
}
}, Can someone help ? i am new to unity: What I would like to do is to make the player rotate left when A is pressed and right when D is pressed. In the past when I try this, it also alters the W and D key(which I have just fixed.
This is my current code for the player:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Move2D : MonoBehaviour { public float moveSpeed = 5f; public bool isGrounded = false; // Start is called before the first frame update void Start() {
}
// Update is called once per frame
void Update()
{
Jump();
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
transform.position += movement * Time.deltaTime * moveSpeed;
}
void Jump()
{
if(Input.GetButtonDown("Jump") && isGrounded == true){
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
}
}
}
Your answer
Follow this Question
Related Questions
Survival Shooter Tutorial: How To Rotate Using Xbox Controller's Right Joystick ? 0 Answers
Roll a ball to the direction it is facing 0 Answers
Prevent Transform Rotation to snap back to 0,0,0 when changing the Control Script 0 Answers
Unity3D accelerometer camera rotation realistic controls 0 Answers
Camera Constantly Rotating 0 Answers