Change collision object/shape values from script


#1

Hi,

I wonder if it is possible to access and modify values like dimension and position for shape objects through code. I need to set those dynamically from script because dimensions and position depend on player’s input. Only other solution I can think of is making a factory and prototype object for all possibilities and spawn one that corresponds to player input. But there are too many of them and it would affect performance dramatically.

Also, I have one more question that may be related to this. Is it possible to add component to game object from script? For example, I want to add that collision object when player does some action, instead of adding it manually.

Thanks in advance
Cheers
Danilo


#2

You cannot set the shapes or dimensions of the collision components at runtime.

And, currently, you cannot change the scale of the physics object by scaling the game object either. We have an issue for that: https://forum.defold.com/t/physic-body-scale-issue-def-521

There is a workaround, and that is that you can set the scale when creating the game object via a game object factory.

ANd, no yo cannot add components at runtime. You can enable/disable components though: https://www.defold.com/ref/go/#disable


#3

Thanks very much for reply. I will try to make it work with that workaround.