Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,24 @@ Now let's define some helper functions for input and math.
(Input/GetKey "a")
(Input/GetKey "s")
(Input/GetKey "d")))


(defn move-forward [^Rigidbody2D rb, distance]
(.MovePosition rb
(v2+ (.position rb)
(v2* (bearing-vector (.rotation rb))
       distance))))
```

We will also make use of layers to manage what bullets can collide with. First add `player`, `enemy`, `player-bullets` and `enemy-bullets` as custom layers in Unity. We do that by clicking `Edit -> Project Settings -> Tags and Layers`, then expand `Layers` and add the layers `player`, `enemy`, `player-bullets` and `enemy-bullets`. Then lets define them in the code so that we don't need to look them up more than once.

```
(def player-bullets-layer (UnityEngine.LayerMask/NameToLayer "player-bullets"))

(def enemy-bullets-layer (UnityEngine.LayerMask/NameToLayer "enemy-bullets"))
```

After that we have to define which layers collides with which. To do that we go to `Edit -> Project Settings -> Physics 2D`, and under `Layer Expansion Matrix` we deselect the collisions between `enemy` and `enemy-bullets`, and between `player` and `player-bullets`. Now all the layers are ready!

### Player Movement

Expand Down