how to create a custom collision box. Please Help!

KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291
edited February 2012 in Working with GS (Mac)
Hello All,
When I have the player collide with an object, the objects hit box is too big. How can I go about creating a hit box which will be close to the shape and size of the object. Hope this is clear enough and if not I can try and explain what I am needing to do another way. Thanks in advance.

Thanks,
killerpenguins

Comments

  • CloudsClouds Member Posts: 1,599
    Gamesalad only allows square, rectangular and circular collision shapes.

    The area of the square, rectangle or circle is defined by the edges of your image file.

    Transparency in an image file has no bearing on collision shape.
  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291
    well the actors I have in my game are a png file which have a transparency background. My player's x is at 50 and when it overlaps/collides with the actor, the actor is about at about 150 and it is destroyed.
  • CloudsClouds Member Posts: 1,599
    edited February 2012
    "well the actors I have in my game are a png file which have a transparency background"

    Transparency in an image file has no bearing on collision shape or area.

    The area of the object is defined by the area of the image file.

    When two objects touch, the rule you have applied will happen (the actor is destroyed in your example).

  • MotherHooseMotherHoose Member Posts: 2,456
    you could create a much smaller invisible actor (just a white square will work … and uncheck its Graphics: Visible when it does so!)
    then constrain that actor's X and Y to the box's X and Y
    and have Player collide with that actor and not the box

    @};- MH
  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291
    thanks guys, I understand what you are saying Tynan, I just figured since I made the pic in PS and it technically does not have a background, the collision box would go with the actual image. I will try your way MotherHoose but not sure how it will work due to the fact that I am creating a distance game where all the actors spawn from off screen at random. With that I will have to make an invisible box for each actor and make sure it spawns in with the actor. I find it annoying that you cant create a precise collision box for each actor. That is one major thing they should implement in gamesalad. Thanks again!

    Thanks,
    killerpenguins
  • CloudsClouds Member Posts: 1,599
    edited February 2012
    @MotherHoose

    "then constrain that actor's X and Y to the box's X and Y"

    I think it is the other way around, you constrain the main actor to the smaller collision box . . . . ?

    (if you want the actor to bounce around the scene that is !)
  • CloudsClouds Member Posts: 1,599
    edited February 2012
    killerpenguins

    "I find it annoying that you cant create a precise collision box for each actor."

    If your actor is square or rectangular or circular it's trivial (automatic even) to create a precise collision box . . . but if you want a complex shaped collision box you are out of luck I'm afraid.

    But . . . if the actor doesn't rotate you can throw a bunch of squares and circles together to create more complex collision areas.
  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291
    edited February 2012
    well if I am in the object and am wanting to constrain it's x and y to the box which is a different actor, how would I go about that. When I bring in the constrain attribute, would I type in the box actor's name in the expression editor so it would read bomb object's self.Position.X = To: collision box.Position.X or how would I go about constraining the two different actors together?
  • MotherHooseMotherHoose Member Posts: 2,456
    the collision area is the actual image area … it is W,H … not pixelFill values … you can crop your images to remove some of the transparent cells
    most times circle collisionShape on both actors works best
    though think it would be great if collision area was confined to Alpha channel fill.

    on the spawnedActor:
    Rule: when
    Attribute: self.Time ≥ 0.1 … or reference another of that actor's attributes
    --spawn the invisible collideSizeActor
        leave the options for direction; positions … at 0 and have both Relative to: actor
        if neither is moveable, you wont have to constrain

    after the collision have the invisible Actor self destruct!

    actually, I like not having to define collision areas! … and know I am a majority of one :|

    many other things you can do to control things … with tags and index attributes …
    and using magnitude you can skip the collision behaviors and reference that to initiate events/actions
    but, that gets yucky for more than a few actors.

    @};- MH
  • CloudsClouds Member Posts: 1,599
    edited February 2012
    @killerpenguins

    "if I am in the object and am wanting to constrain it's x and y to the box which is a different actor, how would I go about that."

    The most straightforward way is to create two game attributes (make them the 'real' type) call them something like FollowX and FollowY.

    Ok, we have two actors, the main one and the other one which will just be used as a collision area for the main one.

    On your collision box actor give it two constrain behaviours:
    Constrain the game attribute called 'FollowX' to the collision box actor's position X.
    Constrain the game attribute called 'FollowY' to the collision box actor's position Y.

    Now we have the two attributes 'FollowX' and 'FollowY' tracking our collision box's every move.

    Now on your main actor also give it two constrain behaviours:
    Constrain the main actor's position X to the game attribute called 'FollowX'.
    Constrain the main actor's position Y the game attribute called 'FollowY'.

    Now the main actor goes wherever the collision box actor goes.
  • MotherHooseMotherHoose Member Posts: 2,456
    @killerpenquin … if you watch some of the videos … you can find the answers to these and many more questions you will have as your project expands.

    GS is easy … but, as you progress to wanting to do more complex things … you should spend some time learning how to.

    after 7 days as a member … you should be proud of your accomplishments … but now you should take some of time to sit back and enjoy some video!
    if things aren't clearer then or not really what you need/want to do, you know that everyone here will help you … :\">

    @};- MH
  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291
    Thank you MotherHoose and I have been trying to watch videos here and there. The issue is that I am going to school for video game design and development and our teacher gave us a week and 2 days to create a game and it's due at 4pm today. LOL so I took it upon myself to learn gamesalad and have my game done in the required time rather than learn and use what my instructor taught me last month and I am just about there. Just a few tweaks here and there and then some polishing and it should be good to go. Thanks for your help and thanks also Tynan. It means a lot to know there are people out there to help.

    Thanks,
    killerpenguins
  • MotherHooseMotherHoose Member Posts: 2,456
    okay … this is an emergency situation …

    fire away with the tweaks you need help with!

    1st suggestions
    - under sceneAttributes make the sceneSize twice the height of your actual game height
    - skip spawning as you want all your actors accessible
    - place your actors in the non-displayable section of your scene
    - try to have their x positions set

    this is bad advice that suits the situation:
    -unlock all your actors' behaviors and work in your actors there
    -name all there actors even if just using X position as name
    -for your actors that are dummy … only used for collisionSize
    - add constrainAttributes: and now when you go to the expressionEditor you will see:
      Current Scene
       select layers and click through till you find the actor you want to constrain it to
    you should only need to constrain the dummyActor

    next ???

    @};- MH
  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291
    Again, thank you so much!!! It truly means a lot. Actually, the post you posted earlier about setting the main actors self.time to >= 0.1 seems to be working great. I tried it on one of the main actors and it destroyed the bomb, the player and played the explosion animation and sound. So now I am on to see if it will work with the other 5 actors which I don't see why it shouldn't. The hardest part for me was that I needed the background to wrap but when turning on scene wrapping everything wraps so to solve the issue, I just have the actors that I don't want to wrap destroy themselves when their self.position.X < 10. I am coming to find that I am having to do a lot of work a rounds in Gamesalad. I am feeling that doing straight coding in action script is a little easier than Gamesalad. LOL
    Again, I can't thank you enough for your time and understanding.

    Thanks,
    Killerpenguins
Sign In or Register to comment.