# Wall collisions and sprite vy

**URL:** <https://forum.makecode.com/t/wall-collisions-and-sprite-vy/481>\
**Category:** Arcade\
**Created:** [August 24, 2019, 7:41pm UTC](https://forum.makecode.com/t/wall-collisions-and-sprite-vy/481 "2019-08-24T19:41:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kjw](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@kjw](https://forum.makecode.com/u/kjw)\
**Post date:** [August 24, 2019, 7:41pm UTC](https://forum.makecode.com/t/wall-collisions-and-sprite-vy/481/1 "2019-08-24T19:41:02Z")

</div>

I wanted to implement damage or loss of life on a fall. That could be done with the `on sprite of kind Player hits wall` if I can determine the impact velocity. I wasn’t sure what the value of the sprite’s `vy` would be when the event fires. Empirically, it works and `vy` is set to what looks like a reasonable `vy` impact velocity.

Reading [Game Loop](https://arcade.makecode.com/developer/game-loop) I am not sure if this is behaviour that is well defined. In the `Physics Step` it says:

> 1. If the sprite is not a ghost and a tile map exists, the sprite is checked for collisions with the tile map. If it has hit something, the sprite may be stopped and an collision event with that type of wall is run.

That could be read as “stopped” meaning `vy` is set to be stationary and then the collision event is processed. That’s not what happens. It would be useful if those documents could address exactly when `vx`/`vy` are altered based on collisions.

Here’s my egg-breaking demonstration code:

 ![arcade-Falling-vy-Experiment-screenshot-code-1](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/fc490405846dfebe24c11253bf323cd49a0ca69f.png)

![arcade-Falling-vy-Experiment](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/f6bb25442716f2e40b483d1b0c553278a4c91605.png)

And here’s first run:

 ![arcade-Falling-vy-Experiment-simscreenshot-run1](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/4b0e8ced5574bb72b3ac333e8093ea39f0a92d20.png)

And a second run where I’m messing with the sim a bit by opening another tab to a popular video site whilst it’s running:

 ![arcade-Falling-vy-Experiment-simscreenshot-run2](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/a91b708970f1bb72b4f3398e1706eb6ca4a69156.png)

This is of lower importance to me but there are a few mysteries in that data:

1. The first two times the event fires both have the impact velocity. The variation is reasonable but the fact the impact velocity is in two events is peculiar and non-intuitive.
2. When the sprite stops `vy` is not set to 0 - it has a value of around 0.4. This is clearly not a floating point rounding issue but something else.
3. The rest value of `vy` fluctuates here, more so when other things are going on in the browser.

Perhaps 2 is due to `ay` being set and it attempting to move the object but the object is not moving so the non 0 `vy` isn’t really correct. I’d imagine 3 is just 2 exacerbated due to a larger delta-t?

---

<div class="post-metadata">

**Author:** ![kjw](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@kjw](https://forum.makecode.com/u/kjw)\
**Post date:** [September 14, 2019, 4:45pm UTC](https://forum.makecode.com/t/wall-collisions-and-sprite-vy/481/2 "2019-09-14T16:45:41Z")

</div>

I observe in the sim that the latest version (v0.14.9) now only has the impact velocity _once_ rather than twice for this. This change appears to make sense and will hopefully this behaviour will be preserved.

The `vy` values for a touching sprite still fluctuate a little around 0.4.
