Finding the X or Y coordinates an actor covers
Meeped
Member Posts: 31
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
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
So I enter that as the coordinates for the random function?
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:
Can you rephrase your question?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
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?
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
So how would that look like in the logic stack?
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.
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
Thing is, I don't know what the Y coordinates I want to spawn at. I want to pinpoint those.
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
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.
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
What would this look like in the rule? That's a lot of equations right there.
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
Yes, but it won't only spawn on the y covered by the actor.
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
@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!
You're welcome!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User