Page 1 of 1

Can CollisionFree access internal actor variables

PostPosted: Fri Dec 22, 2017 11:00 pm
by lverona
Can CollisionFree access internal actor variables, if there actually happens to be a collision? Or is there any way to do this?

CollisionFree is a very easy way to make someone not go through objects without writing huge amount of collision events for all the objects. However, it does not discriminate and an actor using CollisionFree will then bump into everything. I am trying to develop collision groups, which can be done relatively easily with actor variables. But seems that outside of an actual collision event internal actor variables are not accessible.

Re: Can CollisionFree access internal actor variables

PostPosted: Sun Dec 31, 2017 5:25 pm
by lcl
Hello.

Yes, you've ran into the very unfortunate limitation of CollisionFree, the fact that it doesn't make any difference between actors, but counts collision with any actor that has it's CollisionState enabled as a collision. You can try to solve the problem by setting actors' CollisionState to disabled, but even that doesn't work when there's an actor you need to have collision events with, but which shouldn't restrict your movement (collectables, etc.).

I also have tinkered with this particular problem trying to find a solution, but my past attempts haven't been that successful. However, now that you brought this up once again, I tried to work on the problem again, and I think that this time I may have achieved something.

I created a custom function called collisionFreeFromGroup which uses getAllActorsInCollision to find if the proposed new position for an actor creates a collision with any actor that has it's collisionGroup actor variable set to a certain value.

This function requires one extra actor to work. This actor, called collisionMask must have all the same animations (with the same names) as the actor that will use the function. If there's multiple actors that are going to use the function, just add all their animations to the collisionMask actor too. The function will use the exact animation and frame that the checking actor currently has to mimic how the actor would collide if it was moved to the proposed position.

The system also needs two actor variables:
  • collisionGroup (int) - all actors with the same value for this variable are considered part of the same collision group
  • setAnimpos (int) - this variable is used for setting the collisionMask's animpos to the correct value
In the attachment is a little demo of this function in use. The demo also allows you to switch between using my custom function and CollisionFree for detecting collisions, so that you can compare them easily on the fly.

Controls for the demo:
TAB - change collision type
WASD - move

Check it out and see if it helps you with your problem. Also, if you need any help understanding it or applying it to your game, just ask and I'll try to help you! :)