Hi there! Basically, I want my player to simply move along the x-axis only. For some reason this code works, but only if I put the stuff in the FixedUpdate class into an Update class instead. I don’t want that, as I read that FixedUpdate is better for my specific application. And no, I receive no errors. Simply no movement when I try. Even adjusting my speed doesn’t help. Nada. Help please. <3
I feel like this code should do the trick:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public Rigidbody rb;
public float speed;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
}
void FixedUpdated () //Before physics stuff
{
float moveHorizontal = Input.GetAxis ("Horizontal"); //Gets input from keyboard
Vector3 movement = new Vector3(moveHorizontal,0.0f,0.0f);
rb.AddForce(movement*speed*Time.deltaTime);
}
}