Basically I want to use the distance the mouse is to the center of the screen, to determine the speed of the cameras movments. This will allow the player to slowly move the camera if its close to their screen center, and quickly as the player is closer to the edges.
I was able to get the camera moving at a certain speed depending on position on the screen, but as soon as I attempt to dynamic based on distance away from screen center it tells me that the Vector 3 cannot be multiplied (‘*’) by a variable. What do I have to do to fix this?
Here is my prototype camera code:
using UnityEngine;
public class SmoothFollowCamera : MonoBehaviour {
//Static Camera Speed
public int CameraSpeedAcross = 10;
void Update () {
var translation = Vector3.zero;
//Identifies Screen Center
var ScreenCenterWidth = (Screen.width * .5);
//Dynamic Cammera Speed
var CameraMovementAcross = (ScreenCenterWidth - Input.mousePosition.x);
if (Input.mousePosition.x > ScreenCenterWidth)
{
translation += Vector3.right * -CameraMovementAcross * Time.deltaTime ;
}
if (Input.mousePosition.x < ScreenCenterWidth)
{
translation += Vector3.right * CameraSpeedAcross * Time.deltaTime;
}
camera.transform.position += translation;
Are the lines line renderers or gameobjects
– Anonymous620Also, in what directions do you want to detect or do you just want to detect in the direction the player is pointing
– Anonymous620