Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Problems with GetSpriteInCircle

Author
Message
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 4th Sep 2011 14:36
Undoutedly it's something I'm doing (again!)

Anyway, I'm using GetSpriteInCircle to ensure that the player doesn't spawn inside another sprite.

I'm making the call as follows:

So this should keep picking random positions until the function RFS_spawnCheck returns RFS_TRUE (a constant set to 1).

The function looks like this:

It basically loops through all of the rocks, and if there's one inside the circle, it exits the function so another position can be chosen.

However it seems that sometimes the results are ignored and I end up spawning inside a rock. I've tried some debug stuff inside the RFS_spawnCheck function, but occaisonally that gets ignored too.

Not sure what's going on, but any advice would be greatly appreciated.
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 4th Sep 2011 15:56
Function RFS_SpawnCheck()

blah
blah
blah

EndFunction RFS_TRUE


Shouldn't that be ...

EndFunction RFS_SpawnCheck



Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 4th Sep 2011 18:33
Quote: "Shouldn't that be ...

EndFunction RFS_SpawnCheck"

No, because RFS_TRUE is the value that the function passes back. You don't need to specifiy the name of the function at the end.
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 4th Sep 2011 22:02 Edited at: 4th Sep 2011 22:05
Sorry, it was too early in the morning when I looked at it .

You did remember to make that variable Global, right?
You need to use a separate line for that too.

This works...
Global RFS_TRUE
RFS_TRUE = 1


This won't work...
Global RFS_TRUE = 1

Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 5th Sep 2011 00:13
RFS_TRUE and RFS_FALSE are constants, so yes, they're global. But it doesn't make any difference if I replace them with 1 and 0 respectively - I still spawn inside a rock every now and then.
Auger
13
Years of Service
User Offline
Joined: 21st Aug 2011
Location: Out There
Posted: 5th Sep 2011 01:16
Only thing I can think of might be your radius. Not sure how big the player sprite height, is but your checking a circle about 4 times bigger then the player. What size are the rocks?
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 5th Sep 2011 10:50
Quote: "Only thing I can think of might be your radius. Not sure how big the player sprite height, is but your checking a circle about 4 times bigger then the player. What size are the rocks?"

I've tried all sorts of values.

I'm going to code up a little function to draw a circle of 1x1 sprites around the player so I can see exactly how far the circle check extends around the player.

The only thing I can think of is that it isn't as big as I think it is.
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 5th Sep 2011 11:25 Edited at: 5th Sep 2011 11:35
Ignore this post - I made a typo in my circle function. It's now centered on the player properly.

Time for some testing.
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 5th Sep 2011 13:57
Right, so the circle below is centered on the player and has a radius of playerheight*2.



GetSpriteInCircle is called using the same information, and as you can see, the player has appeared with a rock inside the circle. This shouldn't happen.

So either there's a but in GetSpriteInCircle, or something odd is happening when it's working out the radius. Unfortunately with no way of being able to see the circle that GetSpriteInCircle is using, I'm a bit stuck at trying to debug this.
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 6th Sep 2011 13:16
I'm still struggling with this, and it's pretty much the only thing holding me back from finishing.

I think I'm just going to give up with it and make the player invincible for a second or two when they appear.
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 7th Sep 2011 00:35
The invincibility thing doesn't feel right for the game. Looks like my final step is raycasting around the player to see if I get a collision back.

If anyone has time, would you mind trying to code up a quick demo using GetSpriteInCircle to see if it works for you?
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 7th Sep 2011 00:50
I did notice that the rock was entirely inside the circle. I'm guessing the condition is true if the rock is touching the circle's edge line.

I would do this by using a sprite with the image of a circle. Set it small so it's just about the size of the ship. Set it's physics type to kinematic, then scale it's size up until you reach the size of area you want clear around the ship. That should shove the rocks nearby out of the way. (in theory..)

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 7th Sep 2011 10:41
Why not write up a get_distance function to check the distance between the ship and asteroids? If you use the distance formula in theory it should check if a sprite is within a circle because it doesn't matter where the asteroid(s) are in relation to the ship, so long as the distance is large enough the ship can spawn. That's how I would do it.

KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 7th Sep 2011 17:27
Yup, that would be better.

Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 7th Sep 2011 18:21
Right, well I've used GetSpriteInCircle, SpriteRayCaste, and GetSpriteDistance. I've also written my own code for overlapping circle collisions, and distance checks.

In every case the player can spawn too close to the rocks.

I can only guess that the problem must be in how I'm returning information from the detection function. There's only so much you can do with print statements to try and figure out where the problem is, but that's about the only thing I haven't really changed.

ExitFunction is not highlighted in the IDE, but it is listed in the docs, and I'm using it in other parts of my code without apparent problem.

I'm wondering if, because I'm using it inside a loop, it's just bailing out of the loop rather than the function, so I'm getting the wrong value returned.

Just to clarify, the detection code should be called until it returns RFS_TRUE indicating the player is at least the minimum distance away from all rocks.

here's my calling code:


And here's my detection code:
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 7th Sep 2011 23:25
Apparently the GetSpriteDistance command uses up a bit of performance so just keep an eye on your game's performance when testing on mobile devices.

You might be right about the exitfunction bit (I haven't tested it myself) so try this:

I haven't been able to test this however but I'm 90% sure it will work as expected.

Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 8th Sep 2011 00:19
Quote: "Apparently the GetSpriteDistance command uses up a bit of performance "

Not bothered about performance at the moment, I just want it to work right!

I'll have another play with it tomorrow and see what I can come up with.
Airslide
20
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 8th Sep 2011 03:00
To see if your calling code is the problem, you could make your detection code always return false. Then, when you get stuck in an endless loop, you know it is working

Hopefully AppGameKit will get some propper debugger support in the future, since that would probably make life considerably easier.

Login to post a reply

Server time is: 2024-11-23 12:58:46
Your offset time is: 2024-11-23 12:58:46