I aim to enhance my gun’s range dynamically during runtime. If a user opts to upgrade the range, I intend to increase the trigger collision object’s radius. However, it seems challenging to achieve this without scaling the entire object, resulting in an undesired enlargement of the sprite. What would be the optimal approach in Defold? Is it necessary to rescale the entire game object and then readjust the sprite back to its original size afterward?
britzl
December 27, 2023, 3:06pm
2
We very recently merged support for changing the size of collision shapes at runtime:
defold:dev
← defold:dynamic-resize-collision-shapes
opened 12:21PM - 08 Dec 23 UTC
Added script functions to get and set collision shape sizes in runtime. The new … functions are:
``` lua
physics.get_shape(url, shape_name)
physics.set_shape(url, shape_name, table)
```
For example, to update the box shape `my_box` for a collision object located at `/go#collisionobject`:
<img width="441" alt="image" src="https://github.com/defold/defold/assets/169640/6a28d01b-03c7-40a7-8cd7-2090c387a72b">
``` lua
local box = physics.get_shape("/go#collisionobject", "my_box")
box.dimensions = box.dimensions + vmath.vector3(5,10,15)
physics.set_shape("/go#collisionobject", "my_box", box)
```
## PR checklist
* [ ] Code
* [ ] Add engine and/or editor unit tests.
* [ ] New and changed code follows the overall code style of existing code
* [ ] Add comments where needed
* [ ] Documentation
* [ ] Make sure that API documentation is updated in code comments
* [ ] Make sure that manuals are updated (in github.com/defold/doc)
* [ ] Prepare pull request and affected issue for automatic release notes generator
* [ ] Pull request - Write a message that explains what this pull request does. What was the problem? How was it solved? What are the changes to APIs or the new APIs introduced? This message will be used in the generated release notes. Make sure it is well written and understandable for a user of Defold.
* [ ] Pull request - Write a pull request title that in a sentence summarises what the pull request does. Do not include "Issue-1234 ..." in the title. This text will be used in the generated release notes.
* [ ] Pull request - Link the pull request to the issue(s) it is closing. Use on of the [approved closing keywords](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue).
* [ ] Affected issue - Assign the issue to a project. Do not assign the pull request to a project if there is an issue which the pull request closes.
* [ ] Affected issue - Assign the "breaking change" label to the issue if introducing a breaking change.
* [ ] Affected issue - Assign the "skip release notes" is the issue should not be included in the generated release notes.
----------
Example of a well written PR description:
1. Start with the user facing changes. This will end up in the release notes.
1. Add one of the GitHub approved closing keywords
1. Optionally also add the technical changes made. This is information that might help the reviewer. It will not show up in the release notes. Technical changes are identified by a line starting with one of these:
1. `### Technical changes`
1. `Technical changes:`
2. `Technical notes:`
```
There was a anomaly in the carbon chroniton propeller, introduced in version 8.10.2. This fix will make sure to reset the phaser collector on application startup.
Fixes #1234
### Technical changes
* Pay special attention to line 23 of phaser_collector.clj as it contains some interesting optimizations
* The propeller code was not taking into account a negative phase.
```
This will be available in an upcoming release but you can try it already in the 1.6.3 alpha: Release v1.6.3 - alpha · defold/defold · GitHub
5 Likes