I updated the script in my project and I got an error:
Animator' does not contain a definition for 'Getfloat' and no accessible extension method 'Getfloat' accepting a first argument of type 'Animator' could be found (are you missing a using directive or an assembly reference?)
fixed the typo Getfloat on GetFloat;
Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?)
in line 45, I changed the type of the angle variable from int to float;
now the mirror is working a little differently than expected;
Very important: I also understand that this malfunction is not related to adventure creator and you are not obligated to resolve this issue, but nevertheless there is nowhere else to turn.
the final script:
using UnityEngine;
using AC;
public class MirrorCharacter : MonoBehaviour
{
public bool isPlayer;
public AC.Char originalCharacter;
public Animator _animator;
public Vector3 positionOffset;
private void Update ()
{
if (isPlayer)
{
originalCharacter = KickStarter.player;
}
if (originalCharacter == null)
{
return;
}
// Position
transform.position = originalCharacter.transform.position + positionOffset;
// Move speed
if (!string.IsNullOrEmpty (originalCharacter.moveSpeedParameter))
{
float moveSpeed = originalCharacter.GetAnimator ().GetFloat (originalCharacter.moveSpeedParameter);
_animator.SetFloat (originalCharacter.moveSpeedParameter, moveSpeed);
}
// Direction
if (!string.IsNullOrEmpty (originalCharacter.directionParameter))
{
int direction = originalCharacter.GetAnimator ().GetInteger (originalCharacter.directionParameter);
int flippedDirection = FlipDirection (direction);
_animator.SetInteger (originalCharacter.directionParameter, flippedDirection);
}
// Angle
if (!string.IsNullOrEmpty (originalCharacter.angleParameter))
{
float angle = originalCharacter.GetAnimator().GetFloat(originalCharacter.angleParameter);
float flippedAngle = FlipAngle (angle);
_animator.SetFloat (originalCharacter.angleParameter, flippedAngle);
}
// Talking
if (!string.IsNullOrEmpty (originalCharacter.talkParameter))
{
bool isTalking = originalCharacter.isTalking;
_animator.SetBool (originalCharacter.talkParameter, isTalking);
}
}
private float FlipAngle (float angle)
{
// 0 => 0, 90 => 270, 180 => 180, 270 => 90
float mirrored = 360f - angle;
if (mirrored == 360f) return 0f;
return mirrored;
}
private int FlipDirection (int direction)
{
// 0 = Down, 1 = Left, 2 = Right, 3 = Up, 4 = DownLeft, 5 = DownRight, 6 = UpLeft, 7 = UpRight
switch (direction)
{
case 0:
return 3;
case 1:
return 2;
case 2:
return 1;
case 3:
return 0;
case 4:
return 7;
case 5:
return 6;
case 6:
return 5;
case 7:
return 4;
default:
return direction;
}
}
}
Comments
I've updated the Wiki script, try it now.
I updated the script in my project and I got an error:
Animator' does not contain a definition for 'Getfloat' and no accessible extension method 'Getfloat' accepting a first argument of type 'Animator' could be found (are you missing a using directive or an assembly reference?)
fixed the typo Getfloat on GetFloat;
Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?)
in line 45, I changed the type of the angle variable from int to float;
now the mirror is working a little differently than expected;
video: https://imgur.com/a/gy49Tl3
Very important: I also understand that this malfunction is not related to adventure creator and you are not obligated to resolve this issue, but nevertheless there is nowhere else to turn.
the final script:
Try it now.
It works perfectly, you're a legend