Unity Space Shooter Tutorial Player Will Not Move
I should start out by saying that I'm completely new to this sort of thing and know virtually nothing about coding, although I really do want to learn about it. The script will build and save without issue, but when I attach the PlayerController script into the player game object and input the settings for it, the player will tilt, but would not move. For some reason, the script seems to be affecting the camera as well, as whenever I attach the script to the player the camera will zoom in and make it look as if the player was at the center rather than the bottom. Removing the script from the player will revert the camera back to the original position.
Here's my script:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour
{
public Rigidbody rb;
public float speed;
public float tilt;
public Boundary boundary;
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);
Vector3 movement = new Vector3(moveHorizontal, moveVertical, 0.0f );
rb.velocity = movement * speed;
rb.position= new Vector3
(Mathf.Clamp(rb.position.x,boundary.xMin,boundary.xMax),
0.0f,
Mathf.Clamp(rb.position.z,boundary.zMin,boundary.zMax)
);
rb.rotation = Quaternion.Euler(0.0f,0.0f,rb.velocity.x* -tilt);
}
}
I've tried to use several different codes from various "sources" (different comments on YouTube) and for some reason the code on the Unity webpage for the tutorial differs than from the video. Needless to say, none of them changed anything.
Any suggestions at all would be greatly appreciated, even if they don't end up solving the problem.
Thanks in advance.
Answer by zagwyn · Feb 11, 2017 at 08:46 AM
Uncheck "Is Kinematic" on the RigidBody for the Player object.