top of page

Potat

  • apiwatr
  • Mar 11, 2023
  • 2 min read

Project type: Independent

Genre: Platformer

Platform: PC

Year: 2023

Engine : Unity

Game Link: Potat

GitHub : Link


Overview

Potat is a game where you play as a sentiment potato who tried to escape from being cook. Made for the


The game is made is made with an uncoventional control. Being a potato and all there not much way to move around aside rolling and below is how the movement implemented.


Unconventional control

Being a potato put the player in a strange perspective. They can only roll around and movement is limited which create difficulty. Here how the potato control work.

  • Pressing W/S key rolling the potato forward/backward according to the camera direction.

  • Pressing A/D key flip the potato to the side.

Making the control - Forward and rotation

The control of the potato use unity's rigid body system. For the forward/backward movement a forward direction of the camera is use as the direction to apply force to the potato.


        if (onSlope())
        {
            rb.AddForce(slopeMoveDirection * InputController.Instance.movement.y * moveSpeed * 4.5f);
        }
        else
        {
            rb.AddForce(cam.transform.forward * InputController.Instance.movement.y * moveSpeed);
        }

To made the potato rotate toward the camera direction the following step is take.

1. A "gimballer" track the forward direction of the camera and rotate toward it.

public class GimBaller : MonoBehaviour
{
    [SerializeField] private GameObject player;
    [SerializeField] GameObject ballTracker;
    private GameObject cam => Camera.main.gameObject;

    void Update()
    {
        Vector3 targetDirection = new Vector3(ballTracker.transform.position.x, 0, ballTracker.transform.position.z) - new Vector3(transform.position.x, 0, transform.position.z);

        targetDirection.y = 0;

        transform.LookAt(targetDirection * 10);

        Debug.DrawRay(transform.position, targetDirection.normalized * 10,Color.red);
    }
}

2. The potato then lerp to the rotation of the gimballer.

      //rotate potato to camera direction
        if (InputController.Instance.movement.y != 0)
        {
            transform.rotation = Quaternion.Lerp(transform.rotation, gimball.transform.rotation, Time.deltaTime * camLookSpeed);
        }

The result, red line being the direction of gimballer/potato


Admittedly, there is better way for doing this. The gimballer, in theory, could be cut out entirely and rotation value can be calculated directly from the camera. However, due to limited amount of time this method were use instead.


Making the control - Flip

For the flip a game object is added to the side of the potato and upward force is then applied in that position.



//flip the potato
        if (InputController.Instance.movement.x == 1)
        {
            rb.AddForceAtPosition(Vector3.up * -flipSpeed, posRight.transform.position);
        }
        else if (InputController.Instance.movement.x == -1)
        {
            rb.AddForceAtPosition(Vector3.up * -flipSpeed, posLeft.transform.position);
        }

Making the control - Slope

At first the potato where unable to roll up a slope due to it weight. So a solution where made by making shooting a ray to detect slope and increasing the force to help roll the potato.




    public bool onSlope()
    {
        if(Physics.Raycast(transform.position + new Vector3(0,0,0.01f),Vector3.down,out slopeHit, 4))
        {
            if (slopeHit.normal != Vector3.up)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        return false;
    }

Conclusion

Overall, Potat is a challenging project especially given it limited deadline. However, it was a fun little project which teach many thing about unity physic engine.

 
 
 

Opmerkingen


bottom of page