I'm literally ripping my hair out cause of this I've checked this mecanim several times and I keep getting a parsing error CS8025 at lines (4,1), here is the full script. I understand that a parsing error is a syntax error in my script writing - so I've checked that the wiggly brackets all add up and its still giving me this error. Can someone please correct my CSharp script so it works? Code (CSharp): using UnityEngine; using System.Collections; { private Vector3 lastLeftStickInputAxis; // stores the axis input from the left stick between frames } private void Update() { /* START LOCOMOTION */ // Get the axis from the left stick (a Vector2 with the left stick's direction) var leftStickInputAxis = inputManager.LeftAxis; // Get the angle between the the direction the model is facing and the input axis vector var a = SignedAngle(new Vector3(leftStickInputAxis.x, 0, leftStickInputAxis.y), model.transform.forward); // Normalize the angle if (a < 0) { a *= -1; } else { a = 360 - a; } // Take into consideration the angle of the camera a += Camera.main.transform.eulerAngles.y; var aRad = Mathf.Deg2Rad*a; // degrees to radians // If there is some form of input, calculate the new axis relative to the rotation of the model if (leftStickInputAxis.x != 0 || leftStickInputAxis.y != 0) { leftStickInputAxis = new Vector2(Mathf.Sin(aRad), Mathf.Cos(aRad)); } float xVelocity = 0f, yVelocity = 0f; float smoothTime = 0.05f; // Interpolate between the input axis from the last frame and the new input axis we calculated leftStickInputAxis = new Vector2(Mathf.SmoothDamp(lastLeftStickInputAxis.x, leftStickInputAxis.x, ref xVelocity, smoothTime), Mathf.SmoothDamp(lastLeftStickInputAxis.y, leftStickInputAxis.y, ref yVelocity, smoothTime)); // Update the Animator with our values so that the blend tree updates animator.SetFloat("Walk", leftStickInputAxis.x); animator.SetFloat("Turn", leftStickInputAxis.y); lastLeftStickInputAxis = leftStickInputAxis; /* END LOCOMOTION */ /* START ROTATION */ // Get the axis from the right stick (a Vector2 with the right stick's direction) var rightStickInputAxis = inputManager.RightAxis; if (rightStickInputAxis.x != 0 || rightStickInputAxis.y != 0) { float angle2 = 0; if (rightStickInputAxis.x != 0 || rightStickInputAxis.y != 0) { angle2 = Mathf.Atan2(rightStickInputAxis.x, rightStickInputAxis.y)*Mathf.Rad2Deg; if (angle2 < 0) { angle2 = 360 + angle2; } } // Calculate the new rotation for the model and apply it var rotationTo = Quaternion.Euler(0, angle2 + Camera.main.transform.eulerAngles.y, 0); model.transform.rotation = Quaternion.Slerp(model.transform.rotation, rotationTo, Time.deltaTime*10); } /* END ROTATION */ { private float SignedAngle(Vector3 a, Vector3 b) return Vector3.Angle(a, b) * Mathf.Sign(Vector3.Cross(a, b).y); } } Thanks -Finlay Hanlon
That's.... quite a mess, actually. The simplest recommendation is, create a new C# script from Unity (so that it shows you the correct syntax for declaring a class, which is required and completely absent from your pasted code). At the end of your script... I have no idea what's going on there, and neither does the compiler. After "END ROTATION", shouldn't that be a } not a { ? As it is you just have random curly brackets strewn around, and "private" variables declared in a place they have no business being declared.... no wait, that's a function.... but there's no open curly bracket after the function.... Yeah, it's a mess.
Code (csharp): using UnityEngine; using System.Collections; public class YourScriptNameHere : MonoBehaviour { private Vector3 lastLeftStickInputAxis; // stores the axis input from the left stick between frames private void Update() { /* START LOCOMOTION */ // Get the axis from the left stick (a Vector2 with the left stick's direction) var leftStickInputAxis = inputManager.LeftAxis; // Get the angle between the the direction the model is facing and the input axis vector var a = SignedAngle(new Vector3(leftStickInputAxis.x, 0, leftStickInputAxis.y), model.transform.forward); // Normalize the angle if (a < 0) { a *= -1; } else { a = 360 - a; } // Take into consideration the angle of the camera a += Camera.main.transform.eulerAngles.y; var aRad = Mathf.Deg2Rad*a; // degrees to radians // If there is some form of input, calculate the new axis relative to the rotation of the model if (leftStickInputAxis.x != 0 || leftStickInputAxis.y != 0) { leftStickInputAxis = new Vector2(Mathf.Sin(aRad), Mathf.Cos(aRad)); } float xVelocity = 0f, yVelocity = 0f; float smoothTime = 0.05f; // Interpolate between the input axis from the last frame and the new input axis we calculated leftStickInputAxis = new Vector2(Mathf.SmoothDamp(lastLeftStickInputAxis.x, leftStickInputAxis.x, ref xVelocity, smoothTime), Mathf.SmoothDamp(lastLeftStickInputAxis.y, leftStickInputAxis.y, ref yVelocity, smoothTime)); // Update the Animator with our values so that the blend tree updates animator.SetFloat("Walk", leftStickInputAxis.x); animator.SetFloat("Turn", leftStickInputAxis.y); lastLeftStickInputAxis = leftStickInputAxis; /* END LOCOMOTION */ /* START ROTATION */ // Get the axis from the right stick (a Vector2 with the right stick's direction) var rightStickInputAxis = inputManager.RightAxis; if (rightStickInputAxis.x != 0 || rightStickInputAxis.y != 0) { float angle2 = 0; if (rightStickInputAxis.x != 0 || rightStickInputAxis.y != 0) { angle2 = Mathf.Atan2(rightStickInputAxis.x, rightStickInputAxis.y)*Mathf.Rad2Deg; if (angle2 < 0) { angle2 = 360 + angle2; } } // Calculate the new rotation for the model and apply it var rotationTo = Quaternion.Euler(0, angle2 + Camera.main.transform.eulerAngles.y, 0); model.transform.rotation = Quaternion.Slerp(model.transform.rotation, rotationTo, Time.deltaTime*10); } /* END ROTATION */ } private float SignedAngle(Vector3 a, Vector3 b) { return Vector3.Angle(a, b) * Mathf.Sign(Vector3.Cross(a, b).y); } } I THINK that's all of the issues...