- Home /
Character rotates left and right instead of going forward.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TankControls : MonoBehaviour { public GameObject Player; public bool isMoving; public float horizontal; public float vertical;
// Update is called once per frame
void Update()
{
if (Input.GetButton("Horizontal") || Input.GetButton("Vertical")) {
GameObject.FindWithTag("Player").GetComponent<Animator>().Play("Walk");
// Player.GetCompent<Animator>().Play("Walk");
isMoving = true;
horizontal = UnityEngine.Input.GetAxisRaw("Horizontal") * Time.deltaTime * 150.0f;
vertical = UnityEngine.Input.GetAxisRaw("Vertical") * Time.deltaTime * 3.9f;
Player.transform.Rotate(0, horizontal, 0);
Player.transform.Rotate(0, 0, -vertical);
//Vector3 direction = new Vector3(horizontal, 0.0f, vertical).normalized;
Vector3 movement = transform.right * horizontal + transform.forward * vertical;
}
else {
isMoving = false;
//database = GameObject.FindWithTag("Player").GetComponent<Animator>().Play("idle");
GameObject.FindWithTag("Player").GetComponent<Animator>().Play("idle");
}
}
}
Answer by MandMs05whyismynamealwaystakenthisisMYname · May 05, 2021 at 03:34 AM
It's really difficult to read your code and understand what's going on. But it looks like you're using the same buttons to move your player forward and make them rotate. Try using separate buttons for each and see what happens.
Your answer
Follow this Question
Related Questions
rigidbody.AddForce(transform.forward * 5000) 1 Answer
Slowly move a GameObject on 1 axis, then destroy it. 1 Answer
Moving relative to camera direction at constant speed (Velocity problem) 0 Answers
New to Unity & Scripting, How Do I Create a Movement System Thats About Building Up Speed? 0 Answers
How to I put a speed limit on my character's movement? 1 Answer