Brief Summary: I want to recreate Super Mario 64 turning movement into unity without the clunky movement I currently have. And I would also love how to implement the camera rotation system mentioned below.
Troubles: I get lost when thinking into movement algorithms for unity. Like my character won't respond to camera relative movement appropriately. I'll provide a link to a video I made comparing my current basic unity controls to Super Mario 64 if you wish to see the full comparison between the two. And in this video I also mention stuff I think I can do to replicate the things I want. Youtube Link to my comparison video
In-Depth Explanation of the problems with my current movement:
[TurnSpeed ~ My Character turn speed is actually decent. I can increase the value of it to mimic the instant snap turning Mario does when he has a input value of 0. Now when movement is being made, the characters simulate the smooth turning Mario does when given a value of 1 on horizontal input and 1 on vertical input (I usually clamp these values to make it more smooth for people on controllers). Mario: Also as a bonus, when Mario does make a instant snap turn; the camera slowly rotates itself behind the player again to give them the view of the direction they are heading. Estimate Solution: I would love to learn to how exactly make this but so far my guess is getting the direction the player is heading and use that information to rotate the camera using lerp to get it in the right position.]
My Code: I will provide my code for my progress so far in two different fashions: A clean basic movement version on here and a separate code link to see it all.
Full Code Links: CharacterController BasicMovement, and Basic Camera Controls
public Transform T_Player;
private CharacterController CC_PlayerCC;
public float F_CamTurnSpeed;
public float F_CamDistance;
public float F_CamTilt;
public float F_CamTiltLowest;
public float F_CamTiltHighest;
public float F_DirectionItsHeading;
public float F_PlayerHeight;
void start()
{
CC_PlayersCC = GetComponent<CharacterController>();
}
void update()
{
Input();
CalculateCamera();
CalculateGround();
Move();
Gravity();
Jump();
CC_PlayersCC.Move(V3_Velocity * Time.deltaTime);
}
void Input()
{
V2_Input = new Vector2(Input.GetAxis("Horizontal_Keyboard"), Input.GetAxis("Vertical_Keyboard"));
V2_Input = Vector2.ClampMagnitude(V2_Input, 1);
}
void CalculateCamera()
{
V3_CamForwardDirection = T_CameraObj.forward;
V3_CamRightDirection = T_CameraObj.right;
V3_CamForwardDirection.y = 0;
V3_CamRightDirection.y = 0;
V3_CamForwardDirection = V3_CamForwardDirection.normalized;
V3_CamRightDirection = V3_CamRightDirection.normalized;
}
void CalculateGround()
{
if (CC_PlayersCC.isGrounded)
{
B_PlayerIsGrounded = true;
}
else
{
B_PlayerIsGrounded = false;
}
}
void Move()
{
V3_IntendedDirection = V3_CamForwardDirection * V2_Input.y + V3_CamRightDirection * V2_Input.x;
F_CurrentTurnSpeed = V3_Velocity.magnitude / 5;
F_PlayerTurnSpeed = Mathf.Lerp(F_PlayerHighestTurnSpeed, F_PlayerLowestTurnSpeed, F_CurrentTurnSpeed);
if (V2_Input.magnitude > 0)
{
Q_PlayerRotation = Quaternion.LookRotation(V3_IntendedDirection);
transform.rotation = Quaternion.Lerp(transform.rotation, Q_PlayerRotation, F_PlayerTurnSpeed * Time.deltaTime);
}
V3_VelocityXZ = V3_Velocity;
V3_VelocityXZ.y = 0;
V3_VelocityXZ = Vector3.Lerp(V3_VelocityXZ, transform.forward * V2_Input.magnitude * F_PlayerSpeed, F_Accerlation * Time.deltaTime);
V3_Velocity = new Vector3(V3_VelocityXZ.x, V3_Velocity.y, V3_VelocityXZ.z);
}
void Gravity()
{
if (B_PlayerIsGrounded)
{
V3_Velocity.y = F_OnGroundGravity; //OnGround Gravity
}
else
{
V3_Velocity.y -= F_PlayerGravity * Time.deltaTime;
V3_Velocity.y = Mathf.Clamp(V3_Velocity.y, -10, 10);
}
}
void Jump()
{
if (B_PlayerIsGrounded == true)
{
if (Input.GetButtonDown("Jump"))
{
V3_Velocity.y = F_PlayerJumpHeight;
}
}
}
void OnControllerColliderHit(ControllerColliderHit hit)
{
F_CurrentAngle = Vector3.Angle(Vector3.up, hit.normal);
}