Getting an actor to change after a collision

mitchelladjmitchelladj Member Posts: 5
edited May 2012 in Working with GS (Mac)
I have a game where you are the teacher and you are passing out papers to the different students. I have a "Blue Paper" actor constrained to the front of my teacher actor .5 seconds after the teacher spawns. I have another rule that when the Blue Paper collides with the Blue Student, there is a change image to the "Green Paper". This seems pretty simple to me but it just isn't working the way I'm imagining. Ideally I'd like to have a number of random colored students and papers and have each level display a specific number of random colored students. If anyone can provide any guidance on the best way to approach this I would greatly appreciate your help!

http://i50.tinypic.com/2lcb5hj.jpg

Best Answers

  • tatiangtatiang Posts: 11,949
    edited May 2012 Accepted Answer
    I'm assuming that your Blue Student actor is tagged as "desk items" and that the Blue Paper actor does in fact overlap the Blue Student actor and not just the desk itself. Is that right?

    Is at least one of the actors' (Blue Paper and/or Blue Student) "Movable" checkboxes checked?

    Have you tried creating a new actor with the Blue Paper actor's collide & change image rule and making it large enough to definitely collide with the Blue Paper, and then seeing if that new actor's rule works? I'd be curious to see if you added that new actor and a Log Debugging Statement, whether it is in fact colliding (and whether or not it is changing the image as intended).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Posts: 11,949
    Accepted Answer
    One of the two actors has to have "movable" checked for collision detection to work. If you need both to have movable checked, try constraining the actor's x & y position or take off the collide behavior so that it isn't being bumped by the other actor.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Posts: 11,949
    Accepted Answer
    You're welcome! When I do this, I just create a loop with change attribute game.randomPick to random(1,3) and then check to see if game.randomPick is contained in game.alreadyPicked. If not, I do change attribute game.alreadyPicked (text) to game.alreadyPicked..game.randomPick.

    @tshirtbooth also has a helpful video that shows how to choose unique random numbers:

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Answers

  • mitchelladjmitchelladj Member Posts: 5
    edited May 2012
    great, making the student moveable made it work and the paper changed! but now the teacher is able to push the desk around the room, how do i fix it in place?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Uncheck the "movable" box in the desk actor.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • mitchelladjmitchelladj Member Posts: 5
    The desk and the student are the same actor/image. So unchecking the moveable box would undo what I am trying to accomplish. Any way to fix the desk/student in place with the moveable box checked?
  • mitchelladjmitchelladj Member Posts: 5
    Great, I figured it out! Kept the desk unmoveable and made the Blue Paper moveable. Now it works as intended! Thanks for helping me with this, I've been trying to figure this out for days now!

    The intent is now to have the new paper in the teacher's hands change to the color of one of the remaining students in the classroom. So for example the level begins with a green student, a blue student and a red student. The paper that is spawned in the teachers hands is randomly chosen between these three colors. Let's say the red paper is spawned. The teacher then delivers the red paper to the red students desk. The next paper to be spawned should now be one of the two remaining colors, blue or green. Let's say blue is spawned. The teacher then delivers the blue paper to the blue student and the only remaining color, Green, is spawned. The teacher delivers the green paper and the level is complete. Any suggestions on the easiest way to accomplish this?
  • mitchelladjmitchelladj Member Posts: 5
    So what you're saying is I have to assign each color to a number, say blue is "1", red is "2" and green is "3" for instance? How would I do this?
  • mitchelladjmitchelladj Member Posts: 5
    also, what type of attribute should randomPick be, integer?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Yes, you would pick a random number and then based on that number have a rule that says When attribute game.randomPick=1 --> change image to blue (or spawn a blue paper, or however you want to do it).

    game.randomPick would be an integer. game.alreadyPicked would be text.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited May 2012
    @mitchelladj here's a demo I made a while back that generates a list of random numbers: https://www.dropbox.com/s/gfxj9lq3dkj1gej/Pick Random Number from List.zip

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.