Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2016
    Posts
    1

    Exclamation problem with 3rd person character system

    hi all m new here 1st i want to thank 3dbuzz team for these great tutorials m trying to make a 3rd person character camera system while following 3dbuzz tutorials every thing was fine till i reached at this part of tutorial https://www.3dbuzz.com/training/view...istance-theory ( one more thing m totaly beginner for programing so plz sry if its a foolish question )
    problem is that m getting error on "public float DistanceMin = 3f;"
    i watched this video lots of time but i doono why m getting error "Unexpected symbol `float' in class, struct, or interface member declaration" m using unity monodeveloper and mine unity editor version is 5.3.5f1 and heres code m using
    Code:
    using UnityEngine;
    using System.Collections;
    
    public class TP_Camera : MonoBehaviour
    {
    	public static TP_Camera Instance;
    
    	public Transform TargetLookAt;
    	public float Distance = 5f;s
    	public float DistanceMin = 3f;
    	public float DistanceMax = 10f;
    	public float DistanceSmooth = 0.05f;
    	public float DistanceResumeSmooth = 1f;
    
    	public float X_MouseSensitivity = 5f;
    	public float Y_MouseSensitivity = 5f;
    	public float MouseWheelSensitivity = 5f;
    	public float X_Smooth = 0.05f;
    	public float Y_Smooth = 0.1f;
    	public float Y_Minlimit = -40f;
    	public float Y_Maxlimit = 80f;
    
    	public float OcclusionDistanceStep = 0.5f;
    	public int MaxOcclusionChecks = 10;
    
    
    	private float mouseX = 0f;
    	private float mouseY = 0f;
    	private float velX = 0f;
    	private float velY = 0f;
    	private float velZ = 0f;
    
    	private float velDistance = 0f;
    	private float startDistance = 0f;
    	private Vector3 position = Vector3.zero;
    	private Vector3 desiredPosition = Vector3.zero;
    	private float desiredDistance = 0f;
    	private float distanceSmooth = 0f;
    	private float preOccludedDistance = 0;
    
    
    	void Awake()
    	{
    		Instance = this;
    	}
    
    	void Start()
    	{
    		Distance = Mathf.Clamp (Distance, DistanceMin, DistanceMax);
    		startDistance = Distance;
    		Reset ();
    	}
    	
    
    	void LateUpdate()
    	{
    		if (TargetLookAt == null)
    			return;
    
    		HandlePlayerInput ();
    
    		var count = 0;
    		do 
    		{
    			CalculateDesiredPosition ();
    			count++;
    		} while (CheckIfOccluded(count));
    
    		UpdatePosition ();
    	}
    
    	void HandlePlayerInput()
    	{
    		var deadZone = 0.01f;
    		if(Input.GetMouseButton(1))
    		{
    		   // The RMB is down get mouse Axis input
    			mouseX += Input.GetAxis("Mouse X") * X_MouseSensitivity;
    			mouseY += Input.GetAxis ("Mouse Y") * Y_MouseSensitivity;
    		}
    
    		// This is where we will limit mouseY
    		mouseY = Helper.ClampAngle(mouseY,Y_Minlimit,Y_Maxlimit);
    
    		if (Input.GetAxis ("Mouse ScrollWheel") < -deadZone || Input.GetAxis ("Mouse ScrollWheel") > deadZone) 
    		{
    			desiredDistance = Mathf.Clamp(Distance - Input.GetAxis("Mouse ScrollWheel") *MouseWheelSensitivity, 
    				DistanceMin,DistanceMax);	
    			preOccludedDistance = desiredDistance;
    			distanceSmooth = DistanceSmooth;
    		}
    
    	}
    
    
    	void CalculateDesiredPosition()
    	{
    		// Evaluate distance
    		ResetDesiredDistance();
    		Distance = Mathf.SmoothDamp(Distance,desiredDistance, ref velDistance,distanceSmooth);
    
    		// Calculate Desire Position
    		desiredPosition = CalculatePosition(mouseY, mouseX, Distance);
    
    	}
    
    	Vector3 CalculatePosition(float rotationX, float rotationY, float distance)
    	{
    		Vector3 direction = new Vector3 (0, 0, -distance);
    		Quaternion rotation = Quaternion.Euler (rotationX, rotationY, 0);
    		return TargetLookAt.position + rotation * direction;
    	}
    
    	bool CheckIfOccluded(int count)
    	{
    		var isOccluded = false;
    
    		var nearestDistance = CheckCameraPoints (TargetLookAt.position, desiredPosition);
    
    		if (nearestDistance != -1) {
    			if (count < MaxOcclusionChecks) {
    				isOccluded = true;
    				Distance -= OcclusionDistanceStep;
    
    				if (Distance < 0.25f)
    					Distance = 0.25f;
    			} 
    			else
    				Distance = nearestDistance - Camera.main.nearClipPlane;
    
    			desiredDistance = Distance;
    			distanceSmooth = DistanceResumeSmooth;
    		}
    
    		return isOccluded;
    	}
    
    	float CheckCameraPoints(Vector3 from, Vector3 to)
    	{
    		var nearDistance = -1f;
    
    		RaycastHit hitInfo;
    
    		Helper.ClipPlanePoints clipPlanePoints = Helper.ClipPlaineAtNear(to);
    
    		// Draw lines in the editor to make it easier to visualize
    		Debug.DrawLine(from, to +transform.forward * -GetComponent<Camera>().nearClipPlane,Color.red);
    		Debug.DrawLine (from, clipPlanePoints.UpperLeft); 
    		Debug.DrawLine (from, clipPlanePoints.LowerLeft);
    		Debug.DrawLine (from, clipPlanePoints.UpperRight);
    		Debug.DrawLine (from, clipPlanePoints.LowerRight);
    
    		Debug.DrawLine(clipPlanePoints.UpperLeft, clipPlanePoints.UpperRight);
    		Debug.DrawLine(clipPlanePoints.UpperRight, clipPlanePoints.LowerRight);
    		Debug.DrawLine(clipPlanePoints.LowerRight, clipPlanePoints.LowerLeft);
    		Debug.DrawLine(clipPlanePoints.LowerLeft, clipPlanePoints.UpperLeft);
    
    		if(Physics.Linecast(from, clipPlanePoints.UpperLeft, out hitInfo) &&  hitInfo.collider.tag != "Player")
    			nearDistance = hitInfo.distance;
    		
    		if(Physics.Linecast(from, clipPlanePoints.LowerLeft, out hitInfo)&&  hitInfo.collider.tag != "Player")
    		if (hitInfo.distance < nearDistance || nearDistance == -1)
    			nearDistance = hitInfo.distance;
    
    		if(Physics.Linecast(from, clipPlanePoints.UpperRight, out hitInfo)&&  hitInfo.collider.tag != "Player")
    		if (hitInfo.distance < nearDistance || nearDistance == -1)
    			nearDistance = hitInfo.distance;
    
    		if(Physics.Linecast(from, clipPlanePoints.LowerRight, out hitInfo)&& hitInfo.collider.tag != "Player")
    		if (hitInfo.distance < nearDistance || nearDistance == -1)
    			nearDistance = hitInfo.distance;
    
    		if(Physics.Linecast(from, to +transform.forward * -GetComponent<Camera>().nearClipPlane, out hitInfo) && hitInfo.collider.tag != "Player")
    		if (hitInfo.distance < nearDistance || nearDistance == -1)
    			nearDistance = hitInfo.distance;
    
    		return nearDistance;
    	}
    
    	void ResetDesiredDistance()
    	{
    		if (desiredDistance < preOccludedDistance)
    		{
    			var pos = CalculatePosition (mouseY, mouseX, preOccludedDistance);
    
    			var nearestDistance = CheckCameraPoints (TargetLookAt.position, pos);
    
    			if (nearestDistance == -1 || nearestDistance > preOccludedDistance) 
    			{
    				desiredDistance = preOccludedDistance;
    			}
    		}
    	}
    
    	void UpdatePosition()
    	{
    		var posX = Mathf.SmoothDamp (position.x, desiredPosition.x, ref velX, X_Smooth);
    		var posY = Mathf.SmoothDamp (position.y, desiredPosition.y, ref velY, Y_Smooth);
    		var posZ = Mathf.SmoothDamp (position.z, desiredPosition.z, ref velZ, X_Smooth);
    		position = new Vector3 (posX, posY, posZ);
    
    		transform.position = position;
    
    		transform.LookAt(TargetLookAt);
    	}
    
    	public void Reset()
    	{
    		mouseX = 0;
    		mouseY = 10;
    		Distance = startDistance;
    		desiredDistance = Distance;
    		preOccludedDistance = Distance;
    	}
    
    	public static void UseExistingOrCreateNewMainCamera()
    	{
    		GameObject tempCamera;
    		GameObject targetlookAt;
    		TP_Camera myCamera;
    
    		if (Camera.main != null) {
    			tempCamera = Camera.main.gameObject;
    		} else {
    			tempCamera = new GameObject ("Main Camera");
    			tempCamera.AddComponent <Camera> ();
    			tempCamera.tag = "MainCamera";
    		}
    			
    		tempCamera.AddComponent <TP_Camera> ();
    		myCamera = tempCamera.GetComponent ("TP_Camera") as TP_Camera;
    
    		targetlookAt = GameObject.Find ("targetLookAt") as GameObject;
    
    		if (targetlookAt == null) {
    			targetlookAt = new GameObject ("targetLookAt");
    			targetlookAt.transform.position = Vector3.zero;
    		}
    		myCamera.TargetLookAt = targetlookAt.transform;
    	}
    }

  2. #2
    What is the "s" in the line below? Typo?
    public float Distance = 5f;s

  3. #3
    Join Date
    Jul 2010
    Posts
    472
    Quote Originally Posted by ms07 View Post
    Code:
        public float Distance = 5f;s
    Sorry for the late response, you've probably already fixed this, but it was right here. Basically just delete the s and it'll be fine.

    Welcome to 3D Buzz!
    "It's most impressive when it's least expected."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •