Skip to content

Movement

Wildeaso1 edited this page Mar 15, 2024 · 8 revisions

Overview

The players and the NPC's have set coordinates they'd need to move towards. We save the coordinates beforehand by using the Enum extensions. This allows us to save the Player's possible destinations and the NPC's possible destinations.

Written by : William

Usage

UML

---
title: Movement
---
classDiagram
    class BaseMovement{
        # float p_movementSpeed
        # UnityEvent onStartedMoving
        # UnityEvent onStopMoving
        # IEnumerator MoveTowardsGridPoint<T>(T points)
        # StartMoving<T>(T targetPoint)
        # RotateToWalkPoint(Vector3 newPos)
    }
    class PlayerMovement{
        - UnityEvent activateMovingProtocol
        + StartMoving(int playerPoints)
        + StartMovingEvent()
    }
    class NpcMovement{
        + StartMoving(int npcPoints)
    }
    BaseMovement <|-- PlayerMovement
    BaseMovement <|-- NpcMovement
Loading

Flowchart

---
title: Movement
---
flowchart TB

    subgraph BaseMovement
        MoveTowardsGridPoint[MoveTowardsGridPoint]
        StartMoving[StartCoroutine GridPoint]
        RotateToWalkPoint
    end

    Start --> StartMovingEvent
    StartMovingEvent --> StartMoving
    StartMoving --> MoveTowardsGridPoint
    MoveTowardsGridPoint --> RotateToWalkPoint
    RotateToWalkPoint --> StopMoving
    StopMoving --> End


Loading

Base Movement

Methods Return Description
MoveTowardsGridPoint(Enum) Ienumerator This moves the object (Player or NPC) towards a given coordinate from the Enum that is assigned to it's parameter
StartMoving(Enum) void This starts the coroutine that moves the player. In here we assign the enum which contains the coordinates. The enum is a

Playermovement & NPC Movement

Both player movement and NPC movement inherit the basemovement class. Ontop of this they both share one line of code which will allow us to call the function in a UnityEvent

Methods Return Description
StartMoving(int) void With this script we attach the StartMoving(enum) from the basemovement script. That allows us to convert the enum into ints while keeping the functionality.

Source

Down below are links to the script if u wanna take a closer look.

Clone this wiki locally