How to make an actor stick to another actor?
Mayhem_Madness
Member, PRO Posts: 168
Hi everyone, Thor speaking, i wanted to know if you could make an actor stick to another actor, while it moves?
Thankyou.
Thor.
Comments
Yes. Do you want the actors to have their positions synced exactly? If so, constrain attribute game.leaderX (real) to self.Position.X and game.leaderY to self.Position.Y and then in the "follower" actor constrain attribute self.Position.X to game.leaderX and self.Position.Y to game.leaderY.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thankyou, but do you know what i would have to do so they sync together to make a square?
Thankyou.
Thor.
Can you provide a few more details? Maybe a sketch...
I could make a square with four squares that touch corners or four rectangles with space inside the square or four lines... I'm not really sure what you're trying to do.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Yes, it's just a square with four actor squares, one actor square for each side of the square and I want them to all stick together so that they can move together.
Assuming they don't need to rotate, this is pretty straightforward. Here's a demo.
For more complex constraints you might check this out: https://forums.gamesalad.com/discussion/75220/fast-constrain-linkmachine-v2. And here's the original Link Machine: http://forums.gamesalad.com/discussion/62202/linkmachine/p1.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thank you
Do I have to change much, so that It can rotate as well?
Sorry should of said this before.
Yes. See the link I posted.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ok thanks tatiang, you have been great
Hi tatiang, I'm sorry but i should be more clearer, so I'm sorry about that.
But i really wanted it be to be 4 rectangles with space inside, so what would i need to change in that template.
Thankyou.
Thor.
That would be a lot different, especially if you need to rotate them. My template is not a good starting point for something like that.
You might want to upload a screenshot or sketch of what you're doing or better yet a video of similar gameplay to show what you need. It's still not clear what exactly you're trying to do and to be honest I'm not the best person to help you with the trig formulas that are required. Is there a reason you need it be composed of four separate actors?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I have attached a picture of the square i would like, what if i just wanted it to move left and right, not rotate. I want to have space inside the square.
Thanks.
Thor.
I'm kind of hesitant to answer because your needs keep changing. Perhaps you're just wanting to make things simpler, which is fine, but it might help things to explain the larger context here. What type of game are you making? Is it a Tetris-style game where pieces have to fit together or something completely different? Does the square need to collide with other actors? Etc.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Yes i am just trying to make it simpler, so I'm just going to stick with it moving left and right.
Yes it will collide with other actors, and It is something completely different.
Thankyou.
Thor.
Okay, well, you'd need to constrain the x and y positions to be offset from the center. The self.Position.X and self.Position.Y values are at the center of an actor in the scene. So just subtract or add a certain amount to those (as in my demo) and you should be able to get them lined up. It probably would help to draw everything out on paper and label all of the distances/widths so you can come up with the correct expressions.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Hi, im kind of confused on what to put, can you give me an example of what i would put please?
Here's how I would calculate the top piece:
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ok thankyou for that tatiang, much appreciated.
I just wanted to know how would i make that box move left and right by itself?
Thanks.
Thor.
Once you have the positions of the four sides, you could use a Move behavior or Interpolate to change their self.Position.X values.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Can you just tell me if i have done this right, because its not working.
If you constrain the position AND try to Move the actor, those will conflict with each other. Constrain keeps the X and Y positions locked so the actor can't move. You might try switching those out for Change Attribute behaviors.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Yes it worked, i have got it moving to the left, but Its not moving back to the right.
I tried when attribute self.position.x is less than or equal to 76 move in direction 360.
But it just stops, it doesn't move.
Thanks.
Thor.
Can you post a screenshot of your rules?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
ok.
As soon as the actor reaches self.Position.X > 76, it's no longer going to trigger that rule so the actor will stop moving.
You might try something like this (self.direction is an integer and I arbitrarily chose 200 and 400 as the endpoints for movement):
This will toggles the direction between 0 and 180.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ok thankyou, I will try that.
Hi, i can't seem to get it to work, they are not moving left and right together at the same time.
Oh right... oops! They aren't going to reach those endpoints at the same time. You'll have to add an offset value based on each actor's width.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ok, could you give me an example of what I would put please.
Thankyou.
I'm not sure, to be honest. I'd have to work it out. Try sketching as I've done and see what values you come up with. Share those and -- assuming they don't work -- the community can suggest adjustments.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User