How to make "sticky actor"

Talk about making games.

How to make "sticky actor"

Postby xenidius93 » Tue Aug 05, 2014 4:32 pm

I want to make actor,which doesn't detach from the second actor, but how to do this?
Attachments
scheme1.png
xenidius93
 
Posts: 37
Joined: Mon Jul 28, 2014 4:24 am
Score: 1 Give a positive score

Re: How to make "sticky actor"

Postby skydereign » Tue Aug 05, 2014 7:41 pm

Do you want the red sticky actor to stick only to the one gray actor? Or is the sticky actor supposed to stick to many different actors as well? If you just want it to stick to a single gray actor at a time, what you need to do is store a reference to the gray actor you want it to stick to. From there you can prevent the sticky one from ever going beyond a certain distance away from the gray one.
Code: Select all
// this assumes there is only one gray actor for simplicity
int radius = (width + height) / 4; // using an average of height and width for simplicity
int gray_radius = (gray.width + gray.height) / 4;
int max_dist = radius + gray_radius;

if(distance(x, y, gray.x, gray.y) > max_dist))
{
    float ang = direction(gray.x, gray.y, x, y);
    x = gray.x + cos(ang)*max_dist;
    y = gray.y - sin(ang)*max_dist;
}

This is just the idea presented in a simplified form. Since you are dealing with squares you should probably set x and y independently and not use radius. Also the above example would only work with one gray actor, so you would need to use some way of tracking which gray actor a given sticky one is connected to.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How to make "sticky actor"

Postby Zivouhr » Wed Aug 06, 2014 3:00 am

That sounds good Skydereign.

Also, for an actor that follows the lead actor closely, like the body of a snake following the snake's face, the mouse demo where the stars follow the mouse movement might give some tips. Parenting it wouldn't give it any slack but whenever it reached inside the lead actor's Region Zone, it could stick by parenting it to the lead, and falling off if it hits something else, which my first thought about having it stick to the main character. Just some other ideas to think of another possible solution.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: How to make "sticky actor"

Postby xenidius93 » Wed Aug 06, 2014 8:45 am

Hmm, I want to use it, to make a chain from actors "Ring" (red squares at second picture). So I think, that this is not that simple :/.
Attachments
scheme2.png
scheme2.png (717 Bytes) Viewed 1981 times
xenidius93
 
Posts: 37
Joined: Mon Jul 28, 2014 4:24 am
Score: 1 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron