Making This Third Person Adventure Game , I used to be able to move the character left and right , now i can’t, now character only moves it forwards and backwards.
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
public Rigidbody theRB;
public float jumpForce;
// Start is called before the first frame update
void Start()
{
theRB = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
theRB.velocity = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, theRB.velocity.y, Input.GetAxis("Vertical") * moveSpeed);
{
if (Input.GetButtonDown("Jump"))
theRB.velocity = new Vector3(theRB.velocity.x, jumpForce, theRB.velocity.z);
}
}
}`
You show this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
public Rigidbody theRB;
public float jumpForce;
// Start is called before the first frame update
void Start() { theRB = GetComponent<Rigidbody>(); }
// Update is called once per frame
void Update()
{
theRB.velocity = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, theRB.velocity.y, Input.GetAxis("Vertical") * moveSpeed);
{
if (Input.GetButtonDown("Jump"))
theRB.velocity = new Vector3(theRB.velocity.x, jumpForce, theRB.velocity.z);
}
}
}
You’ll notice your curly bracket above Input.GetButtonDown , shouldn’t be there, it should be after input
theRB.velocity = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, theRB.velocity.y, Input.GetAxis("Vertical") * moveSpeed);
if (Input.GetButtonDown("Jump"))
{
theRB.velocity = new Vector3(theRB.velocity.x, jumpForce, theRB.velocity.z);
}
sorry for late reply, im a little confused to where the put the values, can you type in my whole code with your values in them ? that would be great, thanks!