Question by
elliotkoh9 · Apr 27, 2017 at 12:57 PM ·
movement scriptleftright
How to make player move along x axis?
I am making a game where the player is moving automatically with this script
using UnityEngine;
public class MovementForward : MonoBehaviour {
public Rigidbody rb;
public float forwardForce = 2000f;
// Update is called once per frame
void FixedUpdate ()
{
rb.AddForce (0, 0, forwardForce * Time.deltaTime);
if (rb.position.y < -1f)
{
FindObjectOfType<GameManager>().EndGame();
}
}
}
I have buttons which move the player left and right. Right now I am using a script where when I use the buttons, the player goes forwards and backwards. I want to make the player move left and right instead of forwards and backwards. What do I do?
using UnityEngine;
using System.Collections;
public class LeftandRight : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void Left()
{
(GameObject.Find("Player")).transform.Translate(-500f * Time.deltaTime, 0, 0);
}
public void Right()
{
(GameObject.Find("Player")).transform.Translate(500f * Time.deltaTime, 0, 0);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612120631im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
endless runner rotating 0 Answers
problem with scripting movement 1 Answer
How to make the front, left, right, or the back of a gameobject look at a target? 1 Answer
left force right force 0 Answers
so how to i create a moving barrel 0 Answers