61
Ask a Question / Re: Colliding With Actors/Swapping Bools
« on: November 14, 2018, 09:13:45 am »
I would try the following:
- Create a Boolean attribute for your player.
- Randomly assign a "True" or "False" to the attribute when the player is created.
- For your other actors, create a corresponding Boolean attribute.
- When the Actor collides with a member of the actors group, do two things: 1) set the Boolean attribute of "actor of the group" to the same value as the current value of the player's Boolean attribute (use block Behaviours --> Attributes --> "For Actor, set text to anything for behaviour" block), then 2) flip the current value of the player's Boolean attribute (i.e. if attribute is false, set it to true, otherwise set it to false).
This should work because as I understand collisions do not technically happen simultaneously but shortly after one another, so there will always be a flip in the middle.
If you have continuous collisions, the booleans would be constantly changing. If you need to avoid this and make sure the boolean for each actor is only set once, you can introduce a second Boolean for your actors, something like "Value assigned" (default = false). And then for the Collision event, do the following:
If [get the attribute Value assigned from the actor's behaviour] = false, [execute the transfer of the main boolean value from the player to the actor as described at the top of the comment], set the Value assigned in the actor's behaviour to true.
Not sure if this is what you're looking for though.
- Create a Boolean attribute for your player.
- Randomly assign a "True" or "False" to the attribute when the player is created.
- For your other actors, create a corresponding Boolean attribute.
- When the Actor collides with a member of the actors group, do two things: 1) set the Boolean attribute of "actor of the group" to the same value as the current value of the player's Boolean attribute (use block Behaviours --> Attributes --> "For Actor, set text to anything for behaviour" block), then 2) flip the current value of the player's Boolean attribute (i.e. if attribute is false, set it to true, otherwise set it to false).
This should work because as I understand collisions do not technically happen simultaneously but shortly after one another, so there will always be a flip in the middle.
If you have continuous collisions, the booleans would be constantly changing. If you need to avoid this and make sure the boolean for each actor is only set once, you can introduce a second Boolean for your actors, something like "Value assigned" (default = false). And then for the Collision event, do the following:
If [get the attribute Value assigned from the actor's behaviour] = false, [execute the transfer of the main boolean value from the player to the actor as described at the top of the comment], set the Value assigned in the actor's behaviour to true.
Not sure if this is what you're looking for though.