1 decade ago
by phozee
Is there any support for circular collision boxes rather than squares? I am creating a top-down RTS style game. Thinking of how WC3 does it, for example, if you try to run one unit through another, it slides along the edge in a circular motion. Trying something similar with squares doesn't work so well.
I'm not sure how this will always work out, though - currently I have collision type FIXED for the enemy entity and ACTIVE for my player entity. I don't really want either to have the ability to 'push' other entities out of the way, but rather I want them both 'FIXED' in the sense that they will both just try to slide around each other. Setting both entities to FIXED however just acted as if the player was FIXED and enemy was ACTIVE.
I've been working on this for a bit but kinda gave up with "eh, good enough" on mine. However, it only really works for one entity being fixed and the other being "weak".
because what I'm working on is not owned by myself I'm not sure what I cannot share that I've written as far as code goes so I figured it best to just describe it.
I did an .inject plugin on the entity class, giving it a collision shape default to "box" which keeps the current functionality and in the touches function I added a check for collision shape "circle":
this.distanceTo( other ) > this.size.x/2 + other.size.x/2
is a really simple way to check if 2 entities are touching if both are circular (found this on this forum somewhere)
in the seperateOnYAxis and seperateOnXAxis functions if the weak collision shape is a circle I just have it ignore changing it's velocity rather than bouncing off
I also had to do an .inject into the Game class for the checkEntities function to check if the current entity was a circle, and if it was do the circular distance check to see if it still needed to be put into the hash array
which these changes there is a problem when the entity is trying to move at a 45 degree angle while colliding, it just get's stuck because it keeps cycling back and forth between which entity is "on top" and I haven't figured out a good way around it.
edit: I also recommend possibly trying to use box2d since it has circular object physics in it. It was just a bit much for what I needed on my project since I didn't really need a full physics engine and only really needed a bit better collision
1 decade ago
by phozee
Yeah I saw that thread using that method for circular checking but wasn't sure how movement would really work. I'll have to check out Box2d, I'll bet it has what I'm looking for. Thanks for the tips :D
Page 1 of 1
« first
« previous
next ›
last »