Hi,
I am new to Unity as well as C#. I am a C++/C/Java developer. I was trying the first tutorial for creating a player scene from here:
http://www.rebelplanetcreations.com/downloads/Other/Tutorials/HowToMakeAGameInUnity3D.pdf
I keep getting this when I run my C# script:
Look rotation viewing vector is zero
UnityEngine.Quaternion:LookRotation(Vector3)
AIScript:ProcessMovement() (at Assets/Scripts/AIScript.cs:75)
AIScript:Update() (at Assets/Scripts/AIScript.cs:32)
UnityEditor.Toolbar:OnGUI()
The script is as follows:
My player does not move at all. I tried hovering the mouse over and clicking around. What do I do? According to this tutorial, it should work? Please help me.
using UnityEngine;
using System.Collections;
/**
-
AIScript: This class controls AI
-
for objects
-
*/
public class AIScript : MonoBehaviour {//game objects (variables which point to game objects)
private GameObject objPlayer;
private GameObject objCamera;
//input variables (variables used to process and handle input)
private Vector3 inputRotation;
private Vector3 inputMovement;
//identity variables (variables specific to the game object)
public float moveSpeed = 100f;
private bool thisIsPlayer;
// calculation variables (variables used for calculation)
private Vector3 tempVector;
private Vector3 tempVector2;
// Use this for initialization
void Start () {
objPlayer = (GameObject) GameObject.FindWithTag (“Player”);
objCamera = (GameObject) GameObject.FindWithTag (“MainCamera”);
if (gameObject.tag == “Player”) { thisIsPlayer = true; }
}
// Update is called once per frame
void Update () {
FindInput();
ProcessMovement();
if (thisIsPlayer == true)
{
HandleCamera();
}
}
void FindInput ()
{
if (thisIsPlayer == true)
{
FindPlayerInput();
} else {
FindAIinput();
}
}
void FindPlayerInput ()
{
// find vector to move
inputMovement = new Vector3( Input.GetAxis(“Horizontal”),
0,Input.GetAxis(“Vertical”) );// find vector to the mouse
tempVector2 = new Vector3(Screen.width * 0.5f,0,Screen.height *
0.5f); // the position of the middle of the screen
tempVector = Input.mousePosition; // find the position of the moue on screen
tempVector.z = tempVector.y; /input mouse position gives us 2D
coordinates, I am moving the Y coordinate to the Z coorindate in temp Vector and setting the Y
coordinate to 0, so that the Vector will read the input along the X (left and right of screen) and Z
(up and down screen) axis, and not the X and Y (in and out of screen) axis /
tempVector.y = 0;
Debug.Log(tempVector);
inputRotation = tempVector - tempVector2; / the direction we want
face/aim/shoot is from the middle of the screen to where the mouse is pointing/
}
void FindAIinput ()
{
}
void ProcessMovement()
{
rigidbody.AddForce (inputMovement.normalized * moveSpeed * Time.deltaTime);
transform.rotation = Quaternion.LookRotation(inputRotation);
transform.eulerAngles = new Vector3(0,transform.eulerAngles.y + 180,0);
transform.position = new Vector3(transform.position.x,0,transform.position.z);
}
void HandleCamera()
{
objCamera.transform.position = new Vector3(transform.position.x,
15,transform.position.z);
objCamera.transform.eulerAngles = new Vector3(90,0,0);
}
}