Question by
BashiDono · Oct 23, 2017 at 09:59 PM ·
scripting problem
How to move space shooter player
The script isn't working for some reason even if it should. I have kinematic unchecked. My script is : using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour { public Rigidbody rb; public float speed;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.velocity = movement * speed;
}
}
Comment
Are you sure speed
is different from 0
? Have you tried to put a simple Debug.Log( movement ) ;
before setting the velocity?
Answer by connorwforman · Oct 27, 2017 at 03:22 PM
Vector3's are not float variables. Your axis are not being multiplied change the script to this:
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal") * speed;
float moveVertical = Input.GetAxis("Vertical") * speed;
Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);
rb.velocity = movement * speed;
}