I am trying to make a third person controller with C# with a youtube tutorial: Unity 3d Tutorial Advanced Character Controller Template [Outdated] - YouTube
That tutorial is from Unity 3D and I am using Unity 5 so that’s maybe the reason but then how are those scripts different from mines? Can you tell me where is the mistake? [55548-charactermovementthirdperson.txt|55548]
void SetudAnimator();
{
}
“Setud” typo?
Also you have a ; after the (). You should not have this if you want it to read whats in the {}
void ApplyExtraTurnRotation()
{
Missing the closing }
void GroundCheck()
{
if()
{
// Missing closing }
}
There are probably more errors. you should debug your script.
Thanks but still more errors appeared, sorry if I’m causing you too many problems solving this. [55654-charactermovementthirdperson30.txt|55654]
hey @IvanOmega60 I copy pasted your text into vs and removed the typos I saw. A missing semicolon
and a few brackets. So just copy from here and see if it helps.
using UnityEngine;
using System.Collections;
public class CharacterMovement : MonoBehaviour
{
float moveSpeedMultiplier = 1;
float stationaryTurnSpeed = 180;
float movinTurnSpeed = 360;
bool onGround;
Animator anim;
Vector3 moveInput;
float turnAmount;
float forwardAmount;
Vector3 velocity;
float jumpPower = 10;
IComparer rayHitComparer;
// Use this for initialization
void Start();
void SetupAnimator();
public void Move(Vector3 move)
{
if (move.magnitude > 1)
move.Normalize();
this.moveInput = move;
velocity = Rigidbody.velocity;
ConvertMoveInput();
ApplyExtraTurnInput();
GroundCheck();
UpdateAnimator();
}
void SetudAnimator()
{
anim = GetComponent<Animator>();
foreach (Animator childAnimator in GetComponetsInChildren<Animator>())
{
if (childAnimator != anim)
{
anim.avatar = childAnimator.avatar;
Destroy(childAnimator);
break;
}
}
}
void OnAnimatorMove()
{
if (onGround && Time.deltaTime > 0)
{
Vector3 v = (anim.deltaPosition * moveSpeedMultiplier) / Time.deltaTime;
v.y = Rigidbody.velocity.y;
Rigidbody.velocity = v;
}
}
void ConvertMoveInput()
{
Vector3 localMove = Transform.InverseTransformDirection(moveInput);
turnAmount = Mathf.Atan2(localMove.x, localMove.z);
forwardAmount = localMove.z;
}
void UpdateAnimator()
{
anim.applyRootMotion = true;
anim.SetFloat("Forward", forwardAmount, 0.1f, Time.deltaTime);
anim.SetFloat("Turn", turnAmount, 0.1f, Time.deltaTime);
}
void ApplyExtraTurnRotation()
{
float turnSpeed = Mathf.Lerp(stationaryTurnSpeed.movingTurnSpeed, fordwardAmount);
Transform.Rotate(0, turnAmount * turnSpeed * Time.deltaTime, 0);
}
void GroundCheck()
{
Ray ray = new Ray(transform.position + Vector3.up * .1f, -Vector3.up);
RaycastHit[] hits = Physics.RaycastAll(ray, .5f);
rayHitComparer = new RayHitComparer();
System.Array.Sort(hits, rayHitComparer);
if (velocity.y < jumpPower * .5f)
{
//onGround = false;
Rigidbody.useGravity = true;
foreach (var hit in hits)
{
if (!hit.collider.isTrigger)
{
if (velocity.y <= 0)
{
Rigidbody.position = Vector3.MoveTowards(Rigidbody.position, hit.point, Time.deltaTime * 5);
}
onGround = true;
Rigidbody.useGravity = false;
break;
}
}
}
}
class RayHitComparer : IComparer
{
public int Compare(object x, object y)
{
return ((RaycastHit)x).distance.CompareTo(((RaycastHit)y).distance);
}
}
}