# How could I improve my physics engine

**URL:** <https://forum.makecode.com/t/how-could-i-improve-my-physics-engine/31661>\
**Category:** Arcade\
**Tags:** game\
**Created:** [November 12, 2024, 7:04pm UTC](https://forum.makecode.com/t/how-could-i-improve-my-physics-engine/31661 "2024-11-12T19:04:57Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexWuzHereXD](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@AlexWuzHereXD](https://forum.makecode.com/u/AlexWuzHereXD)\
**Post date:** [November 12, 2024, 7:04pm UTC](https://forum.makecode.com/t/how-could-i-improve-my-physics-engine/31661/1 "2024-11-12T19:04:57Z")

</div>

> **[Physics](https://arcade.makecode.com/S54406-50923-60988-33080)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![pumpkinwearingsocks](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/pumpkinwearingsocks/32/19923_2.png) [@pumpkinwearingsocks](https://forum.makecode.com/u/pumpkinwearingsocks)\
**Post date:** [November 12, 2024, 11:53pm UTC](https://forum.makecode.com/t/how-could-i-improve-my-physics-engine/31661/2 "2024-11-12T23:53:04Z")

</div>

I think you could add some intractability so that you can do something instead of watching it, eg being able to throw the object

---

<div class="post-metadata">

**Author:** ![Don](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/don/32/17989_2.png) [@Don](https://forum.makecode.com/u/Don)\
**Post date:** [November 13, 2024, 2:52pm UTC](https://forum.makecode.com/t/how-could-i-improve-my-physics-engine/31661/3 "2024-11-13T14:52:48Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/0/4/045c71f616be82c0562913965cd3f28635e9621a.png)

What you have done here is implement acceleration. Instead you can actually use the sprite’s acceleration to be gravity.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/d/8/d8695fb0d9bb7096b519f1b72b86d057c519d912.png)

What you have done here is create a bounce with some level of slowing down. What you really want is some way to use an event.

Consider this

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/8/6/868eaf7e6748da6c1da7d23ca69aa966c18448b2.png)

What we have done is use the ay (acceleration y) to set up our gravity.  
With gravity we can start our ball with a vy of 0 and let gravity do the work.

We can also set up a wall along the bottom of our tilemap. When we touch the wall we can bounce by setting the vy to -vy and at the same time remove some of the velocity for both x and y.

By using an event instead of _polling_ (looping forever watching for something to happen), we save lots of computing power. That makes our simulation a bit smoother.

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [November 13, 2024, 3:04pm UTC](https://forum.makecode.com/t/how-could-i-improve-my-physics-engine/31661/4 "2024-11-13T15:04:57Z")

</div>

Last post 3 years ago?? Welcome back!!

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [November 13, 2024, 3:05pm UTC](https://forum.makecode.com/t/how-could-i-improve-my-physics-engine/31661/5 "2024-11-13T15:05:01Z")

</div>

Maybe you could set the velocity to 0 once it’s low enough so that the numbers don’t go crazy once it stops moving

---

<div class="post-metadata">

**Author:** ![MicroMan7](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/microman7/32/18103_2.png) [@MicroMan7](https://forum.makecode.com/u/MicroMan7)\
**Post date:** [November 13, 2024, 6:49pm UTC](https://forum.makecode.com/t/how-could-i-improve-my-physics-engine/31661/6 "2024-11-13T18:49:41Z")

</div>

Your off to a good start!

---

<div class="post-metadata">

**Author:** ![AlexWuzHereXD](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@AlexWuzHereXD](https://forum.makecode.com/u/AlexWuzHereXD)\
**Post date:** [November 15, 2024, 7:52pm UTC](https://forum.makecode.com/t/how-could-i-improve-my-physics-engine/31661/7 "2024-11-15T19:52:08Z")

</div>

oh sorry I completely forgot I made this post thanks for the help

---

<div class="post-metadata">

**Author:** ![AlexWuzHereXD](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@AlexWuzHereXD](https://forum.makecode.com/u/AlexWuzHereXD)\
**Post date:** [November 16, 2024, 12:55am UTC](https://forum.makecode.com/t/how-could-i-improve-my-physics-engine/31661/8 "2024-11-16T00:55:00Z")

</div>

this should help and also rn Im working on animations based of directions but this code you sent should help with the ball clipping threw the floor

---

<div class="post-metadata">

**Author:** ![AlexWuzHereXD](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@AlexWuzHereXD](https://forum.makecode.com/u/AlexWuzHereXD)\
**Post date:** [November 18, 2024, 7:15pm UTC](https://forum.makecode.com/t/how-could-i-improve-my-physics-engine/31661/9 "2024-11-18T19:15:48Z")

</div>

I added some stuff with this code try using arrow keys now fyi

---

<div class="post-metadata">

**Author:** ![hihi333444](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/hihi333444/32/18659_2.png) [@hihi333444](https://forum.makecode.com/u/hihi333444)\
**Post date:** [December 9, 2024, 11:44pm UTC](https://forum.makecode.com/t/how-could-i-improve-my-physics-engine/31661/10 "2024-12-09T23:44:09Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/1/6/16af3e60e015a3041069efaf79abe8d95da764f8.png)  
The comment says “You can add left and right here. This is just the bottom. You should probably add the top.” and it is simple addon but it fixes the bottom bounce.

---

<div class="post-metadata">

**Author:** ![hihi333444](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/hihi333444/32/18659_2.png) [@hihi333444](https://forum.makecode.com/u/hihi333444)\
**Post date:** [December 9, 2024, 11:46pm UTC](https://forum.makecode.com/t/how-could-i-improve-my-physics-engine/31661/11 "2024-12-09T23:46:21Z")

</div>

> **[Physics](https://arcade.makecode.com/27377-98463-66302-62918)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

This is the code

---

<div class="post-metadata">

**Author:** ![AlexWuzHereXD](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@AlexWuzHereXD](https://forum.makecode.com/u/AlexWuzHereXD)\
**Post date:** [December 11, 2024, 6:38pm UTC](https://forum.makecode.com/t/how-could-i-improve-my-physics-engine/31661/12 "2024-12-11T18:38:52Z")

</div>

I do not understand, the walls work fine  
I appreciate the gesture but I don’t think there is much to fix.
