# Issue adding collider at runtime

**URL:** <https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621>\
**Category:** Help & Support\
**Created:** [March 26, 2019, 4:39pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621 "2019-03-26T16:39:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![GaLzZy](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/g/c68b51/32.png) [@GaLzZy](https://forum.playcanvas.com/u/GaLzZy)\
**Post date:** [March 26, 2019, 4:39pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/1 "2019-03-26T16:39:51Z")

</div>

Hello, on this project, I have a button which creates a house and then adds a couple components to that house including a mesh collider. I can add the mesh collider from the .json model file in the editor, but when I do it at runtime, if I click the house it looks like it doesn’t have any collider… I don’t know what to do.

Thanks.

Project : [https://playcanvas.com/editor/scene/689436](https://playcanvas.com/editor/scene/689436)

---

<div class="post-metadata">

**Author:** ![GaLzZy](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/g/c68b51/32.png) [@GaLzZy](https://forum.playcanvas.com/u/GaLzZy)\
**Post date:** [March 26, 2019, 4:46pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/2 "2019-03-26T16:46:59Z")

</div>

Ok I got it to work by adding my model file to the collision.model instead of asset, but now it seems like my collider is way bigger than the actual house… How to prevent this ?

---

<div class="post-metadata">

**Author:** ![Nathan\_Hawkins1](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/nathan_hawkins1/32/5715_2.png) [@Nathan\_Hawkins1](https://forum.playcanvas.com/u/Nathan_Hawkins1)\
**Post date:** [March 26, 2019, 4:48pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/3 "2019-03-26T16:48:31Z")

</div>

I cannot see a problem with the collider

---

<div class="post-metadata">

**Author:** ![Nathan\_Hawkins1](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/nathan_hawkins1/32/5715_2.png) [@Nathan\_Hawkins1](https://forum.playcanvas.com/u/Nathan_Hawkins1)\
**Post date:** [March 26, 2019, 4:49pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/4 "2019-03-26T16:49:18Z")

</div>

![55%20PM](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/2X/0/06f3671a190a435f16185999cf3adcfdf0feb848.png)  
you talking about this?

---

<div class="post-metadata">

**Author:** ![GaLzZy](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/g/c68b51/32.png) [@GaLzZy](https://forum.playcanvas.com/u/GaLzZy)\
**Post date:** [March 26, 2019, 4:50pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/5 "2019-03-26T16:50:43Z")

</div>

Nah this one is disabled in the editor… I’m talking about the difference between when you click and unclick the one that is already there when you launch and one that you would create using the blue square at runtime… It seems like the collider of the ones created at runtime is way bigger than it should…

---

<div class="post-metadata">

**Author:** ![Nathan\_Hawkins1](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/nathan_hawkins1/32/5715_2.png) [@Nathan\_Hawkins1](https://forum.playcanvas.com/u/Nathan_Hawkins1)\
**Post date:** [March 26, 2019, 4:54pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/6 "2019-03-26T16:54:01Z")

</div>

No i dont see a problem it all good on my end hmmm try send a screenshot of ur problem if its visible  
EDIT: Nevermind i see what you mean… when you click even away from the building to rotate the camera it pulls the UI for the building right?

---

<div class="post-metadata">

**Author:** ![GaLzZy](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/g/c68b51/32.png) [@GaLzZy](https://forum.playcanvas.com/u/GaLzZy)\
**Post date:** [March 26, 2019, 4:56pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/7 "2019-03-26T16:56:17Z")

</div>

Exactly, but if you try with the one that was created before in the editor, even if you click 1 cm next to it it deselects it compared to the house created at runtime, you have to click really far to unselect it…

---

<div class="post-metadata">

**Author:** ![Nathan\_Hawkins1](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/nathan_hawkins1/32/5715_2.png) [@Nathan\_Hawkins1](https://forum.playcanvas.com/u/Nathan_Hawkins1)\
**Post date:** [March 26, 2019, 4:58pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/8 "2019-03-26T16:58:11Z")

</div>

Yes what seems to be happening is when you move the building the collision moves the opposite direction causing a +/- diversity so now you have to look at the place that makes your building move, when you do that make the collider a positive instead of a negative.

---

<div class="post-metadata">

**Author:** ![GaLzZy](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/g/c68b51/32.png) [@GaLzZy](https://forum.playcanvas.com/u/GaLzZy)\
**Post date:** [March 26, 2019, 5:00pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/9 "2019-03-26T17:00:49Z")

</div>

Ooof i’m not sure I follow you right here to be honest 😮

---

<div class="post-metadata">

**Author:** ![Nathan\_Hawkins1](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/nathan_hawkins1/32/5715_2.png) [@Nathan\_Hawkins1](https://forum.playcanvas.com/u/Nathan_Hawkins1)\
**Post date:** [March 26, 2019, 5:02pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/10 "2019-03-26T17:02:00Z")

</div>

The collider is moving in its own direction instead of updating with the model. i notice its not the same way with all of them some of them they follow but go faster and further

---

<div class="post-metadata">

**Author:** ![GaLzZy](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/g/c68b51/32.png) [@GaLzZy](https://forum.playcanvas.com/u/GaLzZy)\
**Post date:** [March 26, 2019, 5:02pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/11 "2019-03-26T17:02:10Z")

</div>

Don’t you feel that the collider is just wider than it should be ?

---

<div class="post-metadata">

**Author:** ![GaLzZy](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/g/c68b51/32.png) [@GaLzZy](https://forum.playcanvas.com/u/GaLzZy)\
**Post date:** [March 26, 2019, 5:03pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/12 "2019-03-26T17:03:39Z")

</div>

Ohh ok I see what you mean, but how do you manager the position of the collision 😮 Isn’t it actually supposed to be linked with the entity ?

---

<div class="post-metadata">

**Author:** ![GaLzZy](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/g/c68b51/32.png) [@GaLzZy](https://forum.playcanvas.com/u/GaLzZy)\
**Post date:** [March 26, 2019, 5:04pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/13 "2019-03-26T17:04:54Z")

</div>

Actually it makes no sense because even if I don’t move it, it feels way bigger than it should so it’s not the movement the problem

---

<div class="post-metadata">

**Author:** ![Nathan\_Hawkins1](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/nathan_hawkins1/32/5715_2.png) [@Nathan\_Hawkins1](https://forum.playcanvas.com/u/Nathan_Hawkins1)\
**Post date:** [March 26, 2019, 5:05pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/14 "2019-03-26T17:05:51Z")

</div>

Yes something must have happened when you coded the Pos of the building and created the opposite for the collision? Have you tried looking at your code maybe seeing if you can update the collider as well as the entity?

---

<div class="post-metadata">

**Author:** ![GaLzZy](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/g/c68b51/32.png) [@GaLzZy](https://forum.playcanvas.com/u/GaLzZy)\
**Post date:** [March 26, 2019, 5:07pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/15 "2019-03-26T17:07:37Z")

</div>

I am not touching the collider’s position at all… 😮

---

<div class="post-metadata">

**Author:** ![Nathan\_Hawkins1](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/nathan_hawkins1/32/5715_2.png) [@Nathan\_Hawkins1](https://forum.playcanvas.com/u/Nathan_Hawkins1)\
**Post date:** [March 26, 2019, 5:07pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/16 "2019-03-26T17:07:38Z")

</div>

Ok well when moving the entity it is not updating so if you are correct then show the code that allows you to move the buildings. You have to be able to uupdate the collider as you do the entity movement or the collider will just spread every where you move the entity

---

<div class="post-metadata">

**Author:** ![GaLzZy](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/g/c68b51/32.png) [@GaLzZy](https://forum.playcanvas.com/u/GaLzZy)\
**Post date:** [March 26, 2019, 5:09pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/17 "2019-03-26T17:09:05Z")

</div>

The collider is linked to the entity so it must follow it when I move it …

---

<div class="post-metadata">

**Author:** ![Nathan\_Hawkins1](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/nathan_hawkins1/32/5715_2.png) [@Nathan\_Hawkins1](https://forum.playcanvas.com/u/Nathan_Hawkins1)\
**Post date:** [March 26, 2019, 5:14pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/18 "2019-03-26T17:14:32Z")

</div>

Moving the entity is almost like moving something with the mouse the scene has to be updated or the collider will just spread example:  
 ![39%20PM%20-%20Edited](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/2X/4/455e8c66763993ff940304bbccf320773365f264.png)  
The scene starts off with one image but when you move your mouse this happens:  
 ![49%20PM%20-%20Edited](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/2X/5/5040e50e7a36ca199f60a75f4ff9498ed97292c2.png)  
See what im saying the same thing is happening to your colliders  
like so the tracking should happen like so  
 ![Screenshot of what your code should output](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/2X/c/c269656dd6bf652b2e20718d60f574521b7a22a8.gif)

---

<div class="post-metadata">

**Author:** ![GaLzZy](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/g/c68b51/32.png) [@GaLzZy](https://forum.playcanvas.com/u/GaLzZy)\
**Post date:** [March 26, 2019, 5:17pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/19 "2019-03-26T17:17:09Z")

</div>

I’m pretty sure it is not doing this because I was doing the same thing with a box collider earlier and it was working real fine… And if it would be what you say, after couple minutes of moving around, I wouldn’t be able to unclick the house anymore but i’m still able to so I really don’t think there is a spread of collider 😮

---

<div class="post-metadata">

**Author:** ![GaLzZy](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/g/c68b51/32.png) [@GaLzZy](https://forum.playcanvas.com/u/GaLzZy)\
**Post date:** [March 26, 2019, 5:18pm UTC](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621/20 "2019-03-26T17:18:21Z")

</div>

I’m almost 100% sure it is the collider size the problem but idk how to change that to fit the entity because the model i’m applying to the collider is litterally the same as the entity one

[Next page](https://forum.playcanvas.com/t/issue-adding-collider-at-runtime/9621.md?page=2)
