I have been trying to make a movement script for my player in a 2D game but without success. I do not know why it is not working.
The problem is that the player isn't moving. I have a RigidBody attached and gravity on. (Not sure if gravity makes such a difference but I just thought to mention it.)
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public Rigidbody rb;
public float speed = 10;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
float mx = Input.GetAxisRaw("Horizontal");
float mz = Input.GetAxisRaw("Vertical");
Vector3 movement = new Vector3(mx, 0.0f, mz);
Debug.Log(movement);
rb.AddForce(movement * speed * Time.deltaTime);
}
}
movementwhen you adjust the axis? My hunch is that you are adding a force which is not enough to move the object. Checking yourmovement,speed, andTime.deltaTimevariables for proper values would be my first thought.Time.deltaTimeis generally a really small number (1/60-ish). Sincespeedis 10 and the component values ofmovementonly vary between -1 and 1, the final force you add is going to be quite small. Might not be enough to visually overcome the inertia of an object, let alone friction.