HELP!!! Swap actors positions/locations
ToadHouseCreations
Member Posts: 11
Hi everyone.
I have four actors. when i click on 'actor one' and then on 'actor two' i want them to swap positions.
(or seem as if they do by changing images/spawning etc).
I need this to work across all four actors, so that you can click on any two actors and they swap positions. PLEASE HELP ME!!!
I have four actors. when i click on 'actor one' and then on 'actor two' i want them to swap positions.
(or seem as if they do by changing images/spawning etc).
I need this to work across all four actors, so that you can click on any two actors and they swap positions. PLEASE HELP ME!!!
Comments
Cheers
Also, bear in mind I'm not on my Mac, so can't verify any of this.
You have four actors. Let's call them A1, A2, A3 and A4.
Create two global variables for each one - make them integers. You do this by clicking on the 'attributes' tab when looking at a scene. Press the '+' button to add an attribute.
You need two attributes per actor.
For A1: make two attributes called A1X and A1Y
For A2: make two attributes called A2X and A2Y
You get the idea.
Let's make a 'swap' attribute - call it 'swap' and make it a boolean.
Then let's make another boolean attribute for each of the actors. Let's call it 'A1pressed, A2pressed, A3pressed' and so on...
Now, on each of the actors, we have to use a 'constrain' behaviour. So, constrain A1X to 'self.positionX' and A1Y to 'self.positionY' - do the same for the other actors but in Actor 2 use A2X and A2Y, and so on.
Now, we need rules in each actor. We'll use actor A1 as an example. They should go something like:
If attribute 'swap' is false
AND touch is pressed
Change attribute 'A1pressed' to 'true'
Otherwise: change attribute 'A1pressed' to 'false'.
then another rule:
If A1pressed is true
and A2pressed is true
Then:
interpolate self.positionX to A2X in 1 second
interpolate self.positionY to A2Y in 1 second
Change 'swap' to true for however long it takes to move the actors (I've put in 1 second), then after that time, change it back to 'false' (use timers here - e.g. Timer FOR 1 second change swap to 'true'. After 1 second, change 'swap' to false. I'm imagining that this will stop you being able to press more than two actors at once, but not entirely sure).
Do this for the two remaining actors.
Then use this as the basis for each other actor. The rules in Actor A2 would be:
If attribute 'swap' is false
AND touch is pressed
Change attribute 'A2pressed' to 'true'
Otherwise: change attribute 'A2pressed' to 'false'.
then another rule:
If A2pressed is true
and A1pressed is true
Then:
interpolate self.positionX to A1X in 1 second
interpolate self.positionY to A1Y in 1 second
There is probably a much easier way of doing this using Maths or something like touch 1, touch 2 etc but I'm not the Math guy and I'm not at my Mac, sorry!
Hope that helps!
QS
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
Thanks so much for your reply!!! I really appreciate you taking the time to think this one over and leave such a detailed response. Turns out i actually managed to get it working yesterday in the way i first tried. Just re-did all the rules in the exact same way and it worked for some reason! Thought id spend a few days testing it though to make sure there aren't any flaws.
Ive read over your idea and i think this would work also but seeing it took me days to get this functioning i am to scared to scrap my behaviours and retry.
Thanks again for getting back to me i do really appreciate it!
THC