So I saw a thread about what I wanted but there was no anwser.
Sooo… what I want to do is just disable movement in a Y axis.
So Z, X can move everywhere but Y always is 0… well not 0 because it’s parented to an object. But I am doing the camera movement by moving mouse and somehow the Y axis is changing even though I am only changing X, Z axis.
Post the code in question for better help.
Please, take a moment to look at this page before you post your code: Using code tags properly - Unity Engine - Unity Discussions
It will show you how to insert code nicely into the forums.
Oh, thank you for that. And I am sorry but I forgot to change the movement from rotating to changing position. And so sorry for changing topic but I don’t really know how to change the position along axis. If you could help that would be great.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public Transform plyVehicleTran;
public Vector3 camOffset;
public float camAimSpeed = 500f;
float lockPos = 90f;
// Update is called once per frame
void Update () {
transform.position = plyVehicleTran.position + camOffset;
transform.Rotate(new Vector3(0, 0, 0));
if (Input.GetAxis("Mouse X") > 0)
{
transform.position = transform.position.x * Input.GetAxis("Mouse X") * 5 * Time.deltaTime * camAimSpeed;
}
if (Input.GetAxis("Mouse X") < 0)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * 5 * Time.deltaTime * camAimSpeed, 0);
}
if (Input.GetAxis("Mouse Y") < 0)
{
transform.Rotate(-Input.GetAxis("Mouse Y") * 5 * Time.deltaTime * camAimSpeed, 0, 0);
}
if (Input.GetAxis("Mouse Y") > 0)
{
transform.Rotate(-Input.GetAxis("Mouse Y") * 5 * Time.deltaTime * camAimSpeed, 0, 0);
}
}
}
And that code is attached to camera. The line where I tried to change the position is 18. EDIT: Almost forgot… the error is “Cannot implicitly convert type ‘float’ to 'UnityEngine.Vector3”.
Okay, so this thread is just about that error?
A couple of things right away:
- This will only take > 0 Mouse X … so right? No left?
- the error is just as it says. transform.position.x is a float not a Vector3
you could do this:
transform.position = new Vector3(transform.position.x * Input.GetAxis("Mouse X") * 5 * Time.deltaTime * camAimSpeed,transform.position.y,transform.position.z);