- Home /
Question by
raj727 · Jul 30, 2016 at 10:24 AM ·
movementz-axismovementshorizontal movement
X and Z axis question ?
Hey guys. So I am new to unity. bear with me. This is my code. I want the player to be set on position X and move on horizontal axis.. based on left and right inputs and in z direction / forward.. I have declared all the variables and included the header files. so this is my code..i am getting the following errors :
private Vector3 playerPos = new Vector3 (0.25f, 0f, 2.23f);
void Start () {
player = GameObject.FindGameObjectWithTag ("Player");
mainCamera.transform.localPosition = new Vector3 ( 0, 0, 0 );
mainCamera.transform.localRotation = Quaternion.Euler (18, 180, 0);
}
// Update is called once per frame
void Update () {
// player.transform.localPosition.x = posX;
float moveAmount = Time.smoothDeltaTime * 10;
if(mainCamera.transform.localPosition.z >= 0)
{
movementZ = Input.GetAxis("Vertical") * Vector3.forward * moveSpeed * Time.deltaTime;
playerPos = new Vector3 (newX, 0f, movementZ); // says this line has invalid arguments
// also says for the above line.. cannot convert vector 3 to float..
player.transform.position = playerPos;
}
}
can you tell me what i am doing wrong.
thanks.
Comment
Best Answer
Answer by smnerat · Jul 31, 2016 at 04:47 AM
For the error on line 20. You are multiplying by Vector3.forward, which is why you can't set it equal to movementZ.
For the error on line 21, I don't see newX declared anywhere.