Finding the X or Y coordinates an actor covers

This is something I used to know how to do but it just doesn't seem right in testing. I have a spawn actor that covers the outside of the scene and spawns an actor using a random function of the Y coordinate it spans. How can I be sure of which coordinates it spans?

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2015

    The range of Y values would be self.Position.Y ± self.Size.Height. The range of X values would be self.Position.X ± self.Size.Width.

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

  • MeepedMeeped Member Posts: 31

    @tatiang said:
    The range of Y values would be self.Position.Y ± self.Size.Height. The range of X values would be self.Position.X ± self.Size.Width.

    So I enter that as the coordinates for the random function?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2015

    I guess I don't understand what you're asking. I thought you wanted the range of possible x and y values for a given actor in a scene:

    Finding the X or Y coordinates an actor covers
    How can I be sure of which coordinates it spans?

    Can you rephrase your question?

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

  • MeepedMeeped Member Posts: 31

    @tatiang said:

    Can you rephrase your question?

    So, I have a spawner actor that spawns another actor. That spawner is off the camera screen, just outside each border. It spans across the camera border, and I want the actor that is being spawned to spawn randomly on the X or Y coordinate (depending on the border) that the spawner covers over the camera.

    I'm wondering, how do I know what the X or Y coordinates are to plug into the random function in the spawn actor rule?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    It spans across the camera border, and I want the actor that is being spawned to spawn randomly on the X or Y coordinate (depending on the border) that the spawner covers over the camera.

    Okay, I think I get it now. You can use the scene.camera.tracking area.width and height attributes for this. In order to access scene attributes, you have to unlock an actor in the scene.

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

  • MeepedMeeped Member Posts: 31

    So how would that look like in the logic stack?

  • MeepedMeeped Member Posts: 31
    edited February 2015

    What I did was Spawn Actor from position (left the X blank) , random(scene.camera.tracking area.height). It seemed to work but the actors only really spawned in upper half of scene. I don't know if that's coincidence or what.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2015

    Let's say you have a spawner actor on the right edge of the camera area and you want to spawn an actor along that edge but at a random Y position between 0 and 320. You'd do Spawn Actor [x=scene.camera.tracking area.width] [y=random(0,320)] relative to scene.

    Actually, on second thought couldn't you just place the spawner actor on the edge at y=160 and spawn at x=0, y=random(-160,160) relative to actor?

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

  • MeepedMeeped Member Posts: 31

    @tatiang said:
    Let's say you have a spawner actor on the right edge of the camera area and you want to spawn an actor along that edge but at a random Y position between 0 and 320. >

    Thing is, I don't know what the Y coordinates I want to spawn at. I want to pinpoint those.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    I thought you wanted to spawn along the camera edge and I explained how to do that for the right edge.

    Maybe you could sketch what you mean because I'm confused.

    You can upload an image to a file-sharing site and then post the link here. Or use the page icon in the post toolbar if it's available.

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

  • MeepedMeeped Member Posts: 31
    edited February 2015

    http://i58.tinypic.com/i4kbwh.png
    In that image you can see the scene border and camera, and outside of it is the red actor, which is the spawner. I need that to spawn an actor throughout the entire height of the actor, which is Y coordinates. So, I'm using a random function on the Y coordinates.

    http://i61.tinypic.com/ek0myp.png

    This image is the rule, you can see the random function on the Y (ignore the coordinate that's inputted). I want to know what min and max coordinates to put into there, which would be the Y coordinates that the actor ranges.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2015

    Okay, a couple things. The Y range of an actor is self.Position.Y ± self.Size.Height/2. I neglected to include the divisor above, so sorry about that! So if your actor covers the whole scene along the Y axis, as in your image, that's the expression you would use. But another important aspect is that if you spawn an actor relative to actor it won't work using those values. You'd have to leave out the self.Position.Y and just use self.Size.Height/2 or -1*self.Size.Height/2. If you don't want to make your spawner actor huge, you can just use the scene height divided by two instead of the actor height divided by two in your expression.

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

  • MeepedMeeped Member Posts: 31

    What would this look like in the rule? That's a lot of equations right there.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    If your scene size is 1024x768 because you're developing for iPad Landscape and you've placed the spawner actor on the left edge of the camera area at y=384 (768 divided by two) then it would look like this:

    Spawn Actor [x=0] [y=random(-768/2,768/2)] relative to actor

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

  • MeepedMeeped Member Posts: 31

    @tatiang said:

    Spawn Actor [x=0] [y=random(-768/2,768/2)] relative to actor

    Yes, but it won't only spawn on the y covered by the actor.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2015

    So use the height of the actor instead of the height of the scene:

    Spawn Actor [x=0] [y=random(-self.Size.Height/2,self.Size.Height/2)] relative to actor

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

  • MeepedMeeped Member Posts: 31

    @tatiang oh shoot, I just figured my problem out. I didn't realize the middle of the actor determined its coordinates. Thanks for your help!

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    You're welcome!

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

Sign In or Register to comment.