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.

DarkBASIC Professional Discussion / Placing casually 8 plants

Author
Message
Jonathan Archer
11
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 29th Jul 2013 22:24
Hi, my name is Jonathan.
I want to place casually 8 or more plants in a limited area. So I tried to make them to place casually and, if there is a collision with another plant, I change his position. But, because of some reason, the plants overlap.

Sorry, maybe I can't make myself clear because I don't speak english very well. For this, I make the code to speak for me.



Save me, please. Thanks
PirateJohn
13
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 30th Jul 2013 08:25
Maybe you can set some kind of minimum distance between plants. So instead of using "OBJECT HIT" you can use a distance formula.
Jonathan Archer
11
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 30th Jul 2013 15:59
Thanks for the advice, but, as the area is small, the plants would be practically placed in columns and this isn't a pretty sight, isn't it?
What is wrong in my formula? I checked it many times, but It seems correct. I think that there's a problem of collision, but I'm not an expert of collisions. Please, help me
Nabz_32x
16
Years of Service
User Offline
Joined: 25th Oct 2008
Location:
Posted: 30th Jul 2013 17:20
Did you create an object nr 53 in your code?
Or do you get a object does not exist error?

Because when I read the code it checks if object 54 (I assume thats the plants you have created ) and 53 , which I couldn´t spot in your code collide.
Also this is a very inefficient code, which runtime depends on your luck on rand values.

Jonathan Archer
11
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 30th Jul 2013 18:12
That isn't an error. The object 53 exists, but It is an object of the landscape, so It's not possible that It collide.
So, if It's an inefficient code, do you have some advice for me to place casually the plants?
PirateJohn
13
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 30th Jul 2013 20:43
Well, the only other thing I can think of is to place them yourself. Do they have to be randomly placed?
Jonathan Archer
11
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 30th Jul 2013 20:58
Yes
Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 30th Jul 2013 21:10
I think PirateJohn is right..

Instead of doing a collision check, just do a distance check based on your X and Z values, then re-roll your random numbers when needed.

Even if it takes 1000 tries it should still complete in a second or less.

D.D.
PirateJohn
13
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 30th Jul 2013 21:13
Also, depending on what the plants look like, it might not be such a bad thing if they collide a little bit. Plants that live near each other often start to invade each others' space.

Maybe you can link a screenshot or two to give us a better idea of what you're trying to do.
Nabz_32x
16
Years of Service
User Offline
Joined: 25th Oct 2008
Location:
Posted: 30th Jul 2013 21:16 Edited at: 30th Jul 2013 21:19
I would just place them grid based and giving them a randomized Offset on X and Z ( an Offset which makes it impossible that they collide given their grid positions ), making it look more natural.

However here is the code without the logic error I mentioned, still inefficient:

I havent used object hit in years, so I don´t know if it gives you the responce you want, I would just check that the object is not in a rectangular ( or circular ) area, which is defined by another plant object.
Which is a secure way and also it takes less Performance than a poly based dbpro collision.

Jonathan Archer
11
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 31st Jul 2013 00:35
@PirateJohn: Here there is a screenshot of the plants that I want to place. As you can see, all are identical.



@Nabz_32x: Thanks for the code, but I don't understand ocheck<o||ocheck>o. What does it mean?
I want that, when It creates the objects, It verifies their position with the previous object , but only until 54, that is the first plant.
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 31st Jul 2013 06:06
ocheck<o||ocheck>o

|| is OR

if ocheck is less than o or ocheck is greater than o

Shazam!
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 31st Jul 2013 13:56
I would just recycle them. Like, maybe have 6 sprites, and check each one - if it's past the right hand side of the screen, decrease the X position by a screen width plus a random amount, maybe 0 to the width of the screen. So, when a sprite goes off the right, it is moved back between 1 and 2 screens, then it'll scroll off the right again, and be moved back again. That would give you a constant sequence of sprites, positioned fairly randomly.

I got a fever, and the only prescription, is more memes.
Jonathan Archer
11
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 31st Jul 2013 14:43
@Nabz_32x: Finally I understood logic in your code and It's correct, but I tried it and It doesn't work. It's impossible Maybe is the object bugged?

Van B: Thank you for the advice. It's a ingenious idea, but It isn't the result I'm searching
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 31st Jul 2013 15:13


Why use a bitwise operator for that? The disassembly produced is far more inefficient than if you just do this:



@Jonathan Archer

I faintly recall object hit is only updated when sync is called. You could try to change it to object collision instead:



TheComet

Jonathan Archer
11
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 31st Jul 2013 19:11
@TheComet: I replaced it with object collision, but It doesn't work
Nabz_32x
16
Years of Service
User Offline
Joined: 25th Oct 2008
Location:
Posted: 31st Jul 2013 20:17 Edited at: 31st Jul 2013 20:21
Have you scaled your objects manually after loading them?

The Boarders which Object Collision uses aren´t updated then.

Instead of using object collision just use:



@ The Comet:

I know because you´ll need two calls bundled by an OR gatter,
I often Switch through languages and somewhere the <> is not allowed as a single Operator, do you know if DBPro does != ?.

Jonathan Archer
11
Years of Service
User Offline
Joined: 29th Jul 2013
Location: Italy
Posted: 3rd Aug 2013 14:08
@Nabz_32x: I've completely forgot that code. It's a perfect solution! Thanks

Login to post a reply

Server time is: 2024-11-23 14:54:29
Your offset time is: 2024-11-23 14:54:29