# Among Us The Game

**URL:** <https://forum.makecode.com/t/among-us-the-game/5428>\
**Category:** Collaboration\
**Tags:** game\
**Created:** [January 8, 2021, 4:57pm UTC](https://forum.makecode.com/t/among-us-the-game/5428 "2021-01-08T16:57:23Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![xavvvvvv](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/xavvvvvv/32/15324_2.png) [@xavvvvvv](https://forum.makecode.com/u/xavvvvvv)\
**Post date:** [January 29, 2021, 6:53pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/41 "2021-01-29T18:53:22Z")

</div>

I was talking about the classmate thing.

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [January 29, 2021, 7:38pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/42 "2021-01-29T19:38:30Z")

</div>

I am working on it but yet nobody helped me with my issue so currently I can not do anything 😕

---

<div class="post-metadata">

**Author:** ![Agent\_14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agent_14/32/17567_2.png) [@Agent\_14](https://forum.makecode.com/u/Agent_14)\
**Post date:** [January 29, 2021, 8:06pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/43 "2021-01-29T20:06:03Z")

</div>

Hey, have you tried using github to save changes, and revert hem if anything goes wrong?

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [January 29, 2021, 8:22pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/44 "2021-01-29T20:22:51Z")

</div>

No not really

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [February 1, 2021, 5:14pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/45 "2021-02-01T17:14:41Z")

</div>

> [@DahbixLP](#):
>
> Hello! I have started working on Among Us again and I ran into an issue! Paths! I found the path blocks in the Scene category and used them to make an array of paths! At first I made paths from a coordinate to a coordinate but this ended up teleporting the players to their path start point! So I used the position block in the tilemaps extension to make the starting point their own coordinates! First it will lag for 30 seconds bc it sets the path… But everytime a path is done I let it set the path again and it lags again… Any Ideas?
> 
> ![](https://pxt.azureedge.net/blob/e9dfde3b71399a21bd1f586efa4748d0fa6775a0/static/logo.svg) [Microsoft MakeCode](https://arcade.makecode.com/15289-07510-90855-97315)
> 
> ![](https://pxt.azureedge.net/api/15289-07510-90855-97315/thumb)
> 
> ### [Among Us V0.6](https://arcade.makecode.com/15289-07510-90855-97315)
> 
> Made with ❤ in Microsoft MakeCode Arcade.

So This kind of disappeared… I still need help!

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [February 1, 2021, 9:48pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/46 "2021-02-01T21:48:17Z")

</div>

So, path finding is expensive (it takes a lot of time to do, especially on big tilemaps). It looks like every time you are calculating a path, you are actually calculating 7 paths and then randomly choosing one of those.

 ![Screen Shot 2021-02-01 at 1.44.14 PM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/3/30b97f2ed74dd465bb196e566710453423f5a219.png)

Instead, you should randomly choose a _destination_, and then only calculate one path (the one from the current location to that position). If it still feels slow, you can also use the timers extension to put this in the background instead of `on game update`. That will stop it from pausing the game every time it needs to do something that takes a long time.

That logic would look something like this:

```auto
When vx and vy are both 0 and the sprites isn't already looking for a path:
    set is_finding_path to true on the sprite data of the sprite
    inside run separately:
        calculate path
        follow path
        set is_finding_path to false

```

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [February 1, 2021, 10:03pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/47 "2021-02-01T22:03:37Z")

</div>

OK thanks! I will do that! Thanks for the Help! I will tell you if there is something wrong

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [February 2, 2021, 4:03pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/48 "2021-02-02T16:03:50Z")

</div>

Stop path solved! I just set the set kind to body first! Now they stop!

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [February 2, 2021, 4:04pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/49 "2021-02-02T16:04:00Z")

</div>

And also I can not stop them when they get killed… I tried setting velocity, acceleration, both, follow emty array and follow path from its position to its position… But they will keep going! They are switching to be kind body so they will not find another path… but they will complete their current one! Also whenever I kill them they just get a new path… And that path is not any path! It is one of my path list! So what I guess is the person gets killed, then its velocity is 0 for a second so they get a new path and then the kind switches! But I will change that!

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [February 2, 2021, 4:04pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/50 "2021-02-02T16:04:09Z")

</div>

So I changed it and now it does not lag as hard but there is still notacible lag! What should I do?

> **[Among Us V0.6](https://arcade.makecode.com/87936-84620-00247-80763)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

(In the beginning they stay for a bit! Then there is one big lag bc everyone gets a path and then everytime someone gets a new path it lags slightly!)

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [February 2, 2021, 5:46pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/51 "2021-02-02T17:46:35Z")

</div>

There’s no easy solution to this, unfortunately. @jwunderl should there be a pause in the a-star function? maybe only after the path reaches a set length?

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [February 2, 2021, 5:49pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/52 "2021-02-02T17:49:34Z")

</div>

Is it about the lag or the stop?

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [February 2, 2021, 6:04pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/53 "2021-02-02T18:04:09Z")

</div>

The lag. The easiest way to handle the stop would be to throw up a loading screen while you calculate the first set of paths.

That being said, adding a pause to the extension would probably solve everything. The explanation is a little technical, but here goes:

MakeCode has a concept of multi-threading that we call “fibers”. When you call “separately do”, you are creating a new fiber and telling it to run whatever code you put inside. Now there is more than one fiber in the game (the one you created and the one that is running "on game update). When that happens MakeCode will take turns running them. In other words, it will run the “on game update” for a little bit, then run “separately do” for a little bit, then run “on game update” for a little bit, etc.

However, MakeCode will only switch between fibers if one of them calls the “pause” function. Otherwise it will just let whichever one is currently running run until it finishes.

That’s why you have lag right now: even though the path code is inside of a “separately do”, the a-star extension doesn’t call pause so MakeCode needs to wait for it to finish before it can go back to running the game.

Here is an example project that shows this off: [https://makecode.com/\_CTKKh6MsCEe7](https://makecode.com/_CTKKh6MsCEe7)

If you look at the code, it looks like the number should be counting up from 0 to 10000 on the screen. But when it actually runs, it just lags for a while and then shows the number 10000. That’s because the fiber is never pausing so the game can’t update.

If you change the variable “doPause” from false to true, then you will see the number actually count up because the fiber is now letting the game run.

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [February 2, 2021, 6:26pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/54 "2021-02-02T18:26:39Z")

</div>

Hmmm ok I get it! So des that mean I just have to put a pause there? (Like if true)

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [February 2, 2021, 6:55pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/55 "2021-02-02T18:55:17Z")

</div>

No it needs to be done inside the extension, but I’ll leave it up to @jwunderl’s judgement because he wrote the extension.

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [February 2, 2021, 7:00pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/56 "2021-02-02T19:00:08Z")

</div>

Ok! So I’ll have to wait until it will be updated? Well thanks for your help! It works good… In the beginning it has a big lag and everytime a new one is being calculated there is a small lag… But it is playable! And thats what counts! Thanks

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [February 2, 2021, 7:06pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/57 "2021-02-02T19:06:53Z")

</div>

I’m not sure on pausing mid calculation, as I feel like that could cause some weird, hard to explain behavior (e.g. two overlap events storing a temp variable, with the first one calculating a longer path would cause issues) / I wouldn’t expect it to yield to other fibers when calculating something like that personally, but there’s certainly some work that can be done on optimizing the path finding so it runs faster in general – I’ll take a look when I get some extra free time 🙂

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [February 2, 2021, 7:08pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/58 "2021-02-02T19:08:36Z")

</div>

Ok thanks!

---

<div class="post-metadata">

**Author:** ![xavvvvvv](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/xavvvvvv/32/15324_2.png) [@xavvvvvv](https://forum.makecode.com/u/xavvvvvv)\
**Post date:** [February 2, 2021, 7:38pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/59 "2021-02-02T19:38:26Z")

</div>

New version

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [February 2, 2021, 7:49pm UTC](https://forum.makecode.com/t/among-us-the-game/5428/60 "2021-02-02T19:49:13Z")

</div>

The latest one is further up! I will do changes soon!

[Previous page](https://forum.makecode.com/t/among-us-the-game/5428.md?page=2)

[Next page](https://forum.makecode.com/t/among-us-the-game/5428.md?page=4)
