Comments (12)
Indeed Collider adds are queued up to happen in the next frame much like Entity and Component adds. This allows multiple Colliders/Entity/Component additions to happen in one frame keeping the state consistent so that the newly added objects work properly.
One possibility is to add all your colliders at creation time then change their physicsLayer to an unused layer. When you want to activate the collider change it's physicsLayer to the appropriate layer toggling the current Collider to the unused layer. You can then essentially toggle the colliders on/off at will.
I am personally not a big fan of doing things this way but it may work fine for your specific situation. Issues can arise when the Collider is "turned on" if it happens to be overlapping other Colliders. It requires a bit of defensive coding to keep things stable.
An alternative that may work for your situation (I use this a lot for stuff like punches, kicks, sword swings, fast actions that only last a few frames) is to not use a Collider directly at all and instead when the animation frame happens query the Physics class directly.
from nez.
For actual attack collisions I already use the Physics class (which is awesome and works great btw), but the colliders I'm talking about here are for the player itself. Particularly for colliding with terrain and enemies. Certain animations, such as evading and jump kicking, need to alter the player's hit box. I want it to be a mechanic that these animations can potentially reach areas that a normal move or jump wouldn't be able to reach. Ideally I was going to have the main collider change for every frame of the animation, but if that's not possible I suppose I can just create a collider for each animation and switch them when the animation is played.
from nez.
Do you need to change the colliders Shape or just size? If just the size needs to be changed you should be able to do that. If the Shape needs to change that is where multiple Colliders would be required.
from nez.
Just the size. There are a lot of variables packed in a collider and I honestly wasn't sure which to change to modify the size and position without messing up its interaction with the physics system. I don't remember which ones I tried modifying before, but I remember seeing that width/height would be modified in some areas of the collider and not others, making things inconsistent. The collider will always be a BoxCollider, I just need to adjust it to the size/origin of the current animation.
from nez.
Let me give it a look. You should be able to change width/height/offset and it will auto update itself in the SpatialHash.
from nez.
Thanks for the help, sorry for all the questions.
I'm currently experimenting with changing the width, height, and origin of the collider as well as making a new Box shape and changing its position, which seems to adjust the actual size and position properly (if the debug shape outline is any indication) but afterward my player jumps around until it flies off the screen when I move it (using the Mover utility).
from nez.
I should note my animations might be set up a bit different from what you're used to, as each frame of the animation has an adjusted origin upon creation so that it all lines up properly when played. I don't know if that would affect the way calculations are done at all or not.
from nez.
Sprite origin is a separate thing so it shouldn't have any effect on the collider. It definitely sounds like something odd is going on. I'll see what I can find with some testing.
from nez.
Ah, okay. Kinda figured as much but I wasn't sure.
Alright, hopefully it's something minor (like me just doing something wrong). Thanks again for the help, I'll leave you to it until you have some suggestions (or potentially a bug fix if there is one).
from nez.
Found it!
The stupid Box wasnt updating its actual verts when width/height changed.
from nez.
You rock, that works perfectly. Such a simple fix, but it's always the simple ones that slip past us, aye? Thank you so much for the help! :D
You'll hear from me again if something goes awry in the future. :P Great framework, thanks for making it available to everyone like this.
from nez.
Glad to hear it did the trick!
from nez.
Related Issues (20)
- Incompatibility for MonoGame and Nez HOT 1
- Tiled Renderer ignores tileset offset
- Crash when toggling imGui on Linux HOT 1
- Crash when adding FramesPerSecondCounter component in Initialize
- FramesPerSecondCounter draws in world space not in camera space
- How to setup with vscode? HOT 2
- FNA dynamic buffer warning: "Dynamic buffer using SetDataOptions.None, expect bad performance and broken output!"
- Nez.UI ProgressBar is a fixed length HOT 1
- Mathf.AngleBetweenVectors() does not compute the angle between vectors HOT 1
- RendererableComponentList uses unstable sorting algorithm HOT 1
- camera 3d view matrix does not include rotation HOT 1
- Sprite and SpriteAnimator not showing images HOT 1
- Batcher.PushSprite does not round Sprite destination HOT 1
- .Net 7 Support
- Physics.Overlap rect not right size.
- DisposableAsset property not public.
- Installation impossible in VS Code? HOT 1
- Outdated example in FAQs/Rendering.md
- Documentation mistake where CameraBounds is mentioned
- Nez.UI SetScrollBarPositions does opposite of parameter name.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nez.