//Setup; void Awake() { controller = GetComponent <BasicWalkerController>(); animator = GetComponentInChildren <Animator>(); animatorTransform = animator.transform; tr = transform; }
//Setup; void Start() { //Get component references; controller = GetComponent <BasicWalkerController>(); animator = GetComponentInChildren <Animator>(); mover = GetComponent <Mover>(); tr = transform; //Connecting events to controller events; controller.OnLand += OnLand; controller.OnJump += OnJump; if (!animator) { useAnimationBasedFootsteps = false; } }
void SwitchDirection(Vector3 _newUpDirection, BasicWalkerController _controller) { float _angleThreshold = 0.001f; //Calculate angle; float _angleBetweenUpDirections = Vector3.Angle(_newUpDirection, _controller.transform.up); //If angle between new direction and current rigidbody rotation is too small, return; if (_angleBetweenUpDirections < _angleThreshold) { return; } //Play audio cue; audioSource.Play(); Transform _transform = _controller.transform; //Rotate gameobject; Quaternion _rotationDifference = Quaternion.FromToRotation(_transform.up, _newUpDirection); _transform.rotation = _rotationDifference * _transform.rotation; }