- Home /
Player Controller "Horizontal" input convert to "left" and "right"
I am currently creating a game in which the player can drive around on a spherical planet. I wrote the code below with original intentions of publishing it on a pc platform but I decided to convert it over to mobile. What I would like to do is convert what is in the fixed update into two separate voids: a left control and a right control (idk if that makes sense). I guess what I am trying to say is how would I convert
rotation = Input.GetAxisRaw("Horizontal");
into a left and right void? Thanks
public float rotateInBetween = 4f;
public float rotateAdd = 25f;
public float moveSpeed = 5f;
public float rotationSpeed = 200f;
public float accelerationAddSpeed = 0f;
public float accelerationInBetween = 0f;
public float slowMotionLength = 3f;
public float animationSlow = .2f;
private float rotation;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
StartCoroutine(rotateSpeedAdd());
}
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
StartCoroutine(timeSlowPowerUp());
}
rotation = Input.GetAxisRaw("Horizontal");
rotateSpeedAdd();
}
void FixedUpdate()
{
rb.MovePosition(rb.position + transform.forward * moveSpeed * Time.fixedDeltaTime);
Vector3 yRotation = Vector3.up * rotation * rotationSpeed * Time.fixedDeltaTime;
Quaternion deltaRotation = Quaternion.Euler(yRotation);
Quaternion targetRotation = rb.rotation * deltaRotation;
rb.MoveRotation(Quaternion.Slerp(rb.rotation, targetRotation, 50f * Time.deltaTime));
//transform.Rotate(0f, rotation * rotationSpeed * Time.fixedDeltaTime, 0f, Space.Self);
}
Answer by bramieboy100 · Aug 19, 2017 at 09:31 PM
I don't know if you want to check for other input rather than the horizontal axis but you could check in the fixed update if the Input.GetAxisRaw("Horizontal") is greater than zero or below zero. One of them is left and one of them is right.
So something like:
void FixedUpdate (){
if (Input.GetAxisRaw("Horizontal") > 0) {
//Left??
}
if (Input.GetAxisRaw("Horizontal") < 0) {
//right??
}
}
When I read this I totally facepalmed. How did I not think of this lol. Thanks so much!
Your answer
Follow this Question
Related Questions
Smooth walljumping 0 Answers
Character Creeping Backwards 0 Answers
How do i prevent my Player from sliding when i stop walking? 1 Answer
Navmash Pushes Character Controller upwards (0.08, skin width) 0 Answers