# How to shrink an object based on collision through python?

**URL:** <https://blenderartists.org/t/how-to-shrink-an-object-based-on-collision-through-python/1261405>\
**Category:** Game Engine Support and Discussion\
**Tags:** bge\
**Created:** [October 25, 2020, 8:39pm UTC](https://blenderartists.org/t/how-to-shrink-an-object-based-on-collision-through-python/1261405 "2020-10-25T20:39:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saranoske](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@Saranoske](https://blenderartists.org/u/Saranoske)\
**Post date:** [October 25, 2020, 8:39pm UTC](https://blenderartists.org/t/how-to-shrink-an-object-based-on-collision-through-python/1261405/1 "2020-10-25T20:39:08Z")

</div>

I would like to make a sensor object that shrinks when it collides with a wall. Then returns to its original scale when it stops colliding.  
For example:

 ![001](https://blenderartists.org/uploads/default/original/4X/f/c/5/fc58e0e932bed58033892cc75620f3ef739b66d3.png)  
Something like an object that’s 5 units long on its Y scale and shrinking all the way down to 1 unit when colliding with a wall. Then returning to its original length when it stops colliding.

I have tried to code this but it keeps on jittering and won’t stop changing scale.

---

<div class="post-metadata">

**Author:** ![John\_tgh](https://blenderartists.org/user_avatar/blenderartists.org/john_tgh/32/9134_2.png) [@John\_tgh](https://blenderartists.org/u/John_tgh)\
**Post date:** [October 26, 2020, 2:16am UTC](https://blenderartists.org/t/how-to-shrink-an-object-based-on-collision-through-python/1261405/2 "2020-10-26T02:16:40Z")

</div>

Hmmmm, someone else had a similar problem recently… let me see if I can find it.

> [@Character Physics Bug?](https://blenderartists.org/t/character-physics-bug/1256853):
>
> I created a script that takes the vertices of the capsule to be able to divide its positions on the z axis by two when I press the letter C, so far so good, it worked perfectly. But I’m having a problem with Character physics, it “drips” when I use this script on it. Does anyone know if I can solve this? With Character physics: [image] Eat Physics Dynamics (No Sleeping disabled): [[image] ](https://media.giphy.com/media/g0UOT6khnjrRZbB9SU/giphy.gif) With Dynamics physics (No Sleeping enabled): …

There we go, let me know if that helps.

---

<div class="post-metadata">

**Author:** ![Saranoske](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@Saranoske](https://blenderartists.org/u/Saranoske)\
**Post date:** [October 26, 2020, 4:17am UTC](https://blenderartists.org/t/how-to-shrink-an-object-based-on-collision-through-python/1261405/3 "2020-10-26T04:17:46Z")

</div>

Thank you for trying to help me.  
But the topic you’ve shown me shrinks the object by a keypress. What I wanted to achieve is, for the object to gradually shrink when pressing against the wall and then, for it to gradually return to its the original size when it would no longer collide with the wall.  
I was able to code it but it keeps on jittering between sizes.

---

<div class="post-metadata">

**Author:** ![John\_tgh](https://blenderartists.org/user_avatar/blenderartists.org/john_tgh/32/9134_2.png) [@John\_tgh](https://blenderartists.org/u/John_tgh)\
**Post date:** [October 26, 2020, 6:25pm UTC](https://blenderartists.org/t/how-to-shrink-an-object-based-on-collision-through-python/1261405/4 "2020-10-26T18:25:36Z")

</div>

Hmmm… Is the collission detection necessary? It just seems like the wrong approach to me - but then I don’t know exactly what your usecase is. Could a raycast be used instead? I imagine the raycast would give you pixel-perfect scaling values, and therefore no jittering at all?

---

<div class="post-metadata">

**Author:** ![edderkop](https://blenderartists.org/letter_avatar_proxy/v4/letter/e/f475e1/32.png) [@edderkop](https://blenderartists.org/u/edderkop)\
**Post date:** [October 26, 2020, 7:23pm UTC](https://blenderartists.org/t/how-to-shrink-an-object-based-on-collision-through-python/1261405/5 "2020-10-26T19:23:39Z")

</div>

this is pretty simple to make using animated shapekeys.

[animated-shapekeys.blend](https://blenderartists.org/uploads/short-url/wKAbEoUulsAa2zKDlxr7dGuOjqb.blend) (526.7 KB)  
(Demo made in blender 2.79)

 ![image](https://blenderartists.org/uploads/default/original/4X/c/8/8/c8813ccc5aabe96b7c5116719bba0015e7f30a41.png)

---

<div class="post-metadata">

**Author:** ![Saranoske](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@Saranoske](https://blenderartists.org/u/Saranoske)\
**Post date:** [October 28, 2020, 3:30pm UTC](https://blenderartists.org/t/how-to-shrink-an-object-based-on-collision-through-python/1261405/6 "2020-10-28T15:30:16Z")

</div>

I wanted to create a sensor for the camera but a ray sensor did the job, thanks.

---

<div class="post-metadata">

**Author:** ![Saranoske](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@Saranoske](https://blenderartists.org/u/Saranoske)\
**Post date:** [October 28, 2020, 3:32pm UTC](https://blenderartists.org/t/how-to-shrink-an-object-based-on-collision-through-python/1261405/7 "2020-10-28T15:32:17Z")

</div>

Thank you for the demo. In the end, I have decided to use something else but this might be helpful in the future.

---

<div class="post-metadata">

**Author:** ![abulalashaikh](https://blenderartists.org/user_avatar/blenderartists.org/abulalashaikh/32/1484058_2.png) [@abulalashaikh](https://blenderartists.org/u/abulalashaikh)\
**Post date:** [July 1, 2026, 12:38am UTC](https://blenderartists.org/t/how-to-shrink-an-object-based-on-collision-through-python/1261405/8 "2026-07-01T00:38:33Z")

</div>

Hey Can you help me out with collision detection ?
