I made this simple movement type based on the Top Down movement type. In a top down scenario, the character moves with WASD or one stick AND looks in the movement direction:
However, when shooting, the character always turns to 0° (facing north) and then fires in the previous angle. E.g. I go South, press fire, the character turns to North but the magic ball spawns and flies South. I guess I have to edit the shoot direction as well?
C#:
public class OneAxisTopDownMovement : MovementType
{
public override bool FirstPersonPerspective { get { return false; } }
public override float GetDeltaYawRotation(float characterHorizontalMovement, float characterForwardMovement, float cameraHorizontalMovement, float cameraVerticalMovement)
{
if (characterHorizontalMovement != 0 || characterForwardMovement != 0)
{
var inputVector = Vector3.zero;
inputVector.Set(characterHorizontalMovement, 0, characterForwardMovement);
var lookRotation = Quaternion.LookRotation(Quaternion.identity * inputVector.normalized);
return MathUtility.ClampInnerAngle(MathUtility.InverseTransformQuaternion(m_Transform.rotation, lookRotation).eulerAngles.y);
}
else
return 0;
}
public override Vector2 GetInputVector(Vector2 inputVector)
{
if (inputVector.magnitude != 0)
return (new Vector2(0, 1));
else
return Vector2.zero;
}
}
However, when shooting, the character always turns to 0° (facing north) and then fires in the previous angle. E.g. I go South, press fire, the character turns to North but the magic ball spawns and flies South. I guess I have to edit the shoot direction as well?