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 / Enemy line of sight

Author
Message
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 27th Sep 2017 00:16
How would i go about determining an objects line of sight? I am creating a simulation game which would require the objects cast a line in front of the direction they are looking and determine which if any objects it hits. If its food in front of them i want them to go towards it, if its an enemy away from it ect. Perhaps i am misunderstanding the intersect object command but it seems like this only returns a distance to a specific object and would be useless for what i am attempting to do.
Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 27th Sep 2017 08:02
That depends on your scenario
Do you have objects that may hide your food/enemy ones depending on your position?
Do you have many "characters" that need to check at once if food/enemies are visible/not visible ?
Do you need your line of sight to be precisely lined-up with your characters angle or just need to know if food/enemy objects are visible/not visible from any angle?

things might get a bit complicated depending on yur precise needs

I'll include a code snippet for visible/not visible routine but based only on one player and one enemy

If that's more or less what you need it can be expanded for multiple objects

Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 27th Sep 2017 08:47
Each creature, is a square or a sphere at this point, basically I just want to check a short distance in front of them, perhaps 100 units or so and see if there is anything within their line of sight. If so I am going to use the information about the object it can see to determine its future action.
I need to run this on as many creatures as possible.

Quote: "Do you have objects that may hide your food/enemy ones depending on your position?"

My position is kind of irrelevant since i am just an observer of the simulation at the moment.



I attempted to make my own raycaster as I am experienced in this area and use an object so that I could just use internal object detection and where as this worked great performance suffered to say the least lol. It dropped from like 30fps to 3 :p
It raycasted a tiny Object from the players line of sight and detected for collision using Object collision command, easy and straight forward as well as effective yet impossibly slow. Come to think of it that was not 30 - 3 FPS because i had to remove about 700 creatures just to get it to work so its totally out the window.

Quote: "Do you need your line of sight to be precisely lined-up with your characters angle or just need to know if food/enemy objects are visible/not visible from any angle?"


Its not really a requirement I guess but I really like the idea of them literally being able to see in front of them as It will more then likely aid me in future development but if I find frame rate becomes and issue then I will resort to work around late down the line.


I just got sparky DLL a few moments ago but still can't seem to get it to return a value just yet so I will probably just make a small experimental program to get the hang of it tomorrow.


Thank you for the code, I will attempt to dissect it in the morning and respond accordingly, it is 4 in the morning here and since I started coding again for the first time in about 15 years I once again stopped sleeping so it might be best if I take this on tomorrow else im going to see the sun rise again for sure.
zero32
7
Years of Service
User Offline
Joined: 28th Jul 2016
Location:
Posted: 27th Sep 2017 08:50
as far as i understand, the intersect object command gives the distance to the object you specify in the command. it is useful for enemies to detect the player but i would not know how to detect if a wall blocks the line of sight.
you could try something like this, but it may result in bad performance. i didn't test this:

insert your values.

i would not know of any other way with the normal dark basic pro commands, but if you use sparkys collision plugin, you could do all of that in just one raycast, but you would have to change the collision detection completely.
link to the plugin: https://forum.thegamecreators.com/thread/74762?page=1
Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 27th Sep 2017 14:59
Well this is a basic attempt
I'm using the square root distance calculation
Not knowing what should happen when the characters reach the food they just get stuck there at the moment
The example is based on 20 moving characters, 20 still enemies and 20 foods
Cheers

Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 27th Sep 2017 22:12
Zero32, I feel like cycling through all the creatures is going to make way to much of a dent on performance as I currently can run 300 "trees" which are food and 600 creatures M/F. I would like to eventually optimize my code to include more in the future but I may just have to go back to my C++ roots for that to happen however at the moment I love being able to toy around with the code without having to worry about low level stuff as I would using C++.

Scorpyo I like the code you have and the idea of using cones showing the creature direction is a nice touch i might implement soon enough. So what is taking place if i am dissecting this correctly is if the creature is with 300 of food it heads towards it correct? I altered the value to get a frame rate comparison and your code even up to 500 creatures 100 enemy and 100 food still ran around 28fps on my shitty system which is not bad at all.


Here is what I am currently working with, mind you I have not programmed in around 15 years and never in DB until about 2 weeks ago so i am sure there is much more that can be done.

Arrow keys and the mouse control the camera.
Creatures all currently are part of the same Array but that will likely change in the future.
When a Male(Red box) contacts a Female Blue box the have a small chance to breed(something like 1 in 10 or something cant remember what its set at right now). When they breed another creature is created with the idea of their "genetics" passing down information to the offspring. They remember the position they breed and will return there when their health is full
When two Boxes collide of the same sex they fight and remember this position avoiding it for future cycles by turning away from it.
Boxes are scaled according to Age.

When their health due to fighting and age decreases to a low level they seek food and return to the last place they contacted food which is the green cones. The cones maintain a steady 300 for the most part, they are scaled accordingly to health

You can see i have a type Neuro_transmitters, this is for near future work and the levels of each are going to more accurately determine the behavior of the creature.

Trying to think if there is anything else to add so you can get an idea of what is going on in the chaos...

at 500 days old a creature starts to lose health with every cycle due to old are.

Creature will tend to cluster around food which you will see and if they have never feed before getting into a fight at the moment they will haul ass and run completely off the world to die lol. Those that hide in the middle of food clumps managed to beat my attempts to kill them at the age of 500 and some have been seen to live over 8000 days old by feeding whenever their health gets low.

I tend to run around 20fps at the moment but im sure when i move the trees to their own array that will speed up.
I guess thats it for the moment.

You can see how i want them to be able to see like 50 places ahead to determine if they should avoid the area or run towards it. I want "vision" so they will be able to scan an area if they see nothing to turn the creature in various directions instead of it being relatively random when they turn at the moment.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 28th Sep 2017 00:56
Sorry if this is excessive posting but I have come to another error and dont know how to edit my post since they seem to need mod approval...
Why is this not placing object 3000 100 units ahead of the object last_select?

x=OBJECT POSITION X (last_select)
y=OBJECT POSITION y (last_select)
z=OBJECT POSITION z (last_select)
tox=newxvalue(x,object angle x(last_select),100)
toy=NEWYVALUE(y,OBJECT ANGLE Y(LAST_SELECT),100)
toz=newzvalue(z,object angle z(last_select),100)
print "detected:";sc_raycast(0,x,y,z,tox,toy,toz,last_select)

position object 3000,tox,toy,toz

its instead staying t o one side of the object and jumping around aimlessly, this is something i will need to figure out if i am to get any raycasting to work correctly
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 28th Sep 2017 02:10
Hi there

The command Intersect object ,not only gives you the distance but also tells you if there is something that intersects between the two points (your point and the food/enemies etc) .
I made a litle example that shows you how it works.







I'm not a grumpy grandpa
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 29th Sep 2017 06:25 Edited at: 29th Sep 2017 06:26
I have put some thought into it and I think an effective and fast method might be to just make a triangle at the front of the creature and detect collisions with it, I will more then likely be better then raycasting as I will be able to check where in its vision it is instead of just telling if its directly infront of it. I could use the information to turn towards or away depending on what its viewing and where in the viewing area it is.

Only issue i see at the moment is I do not currently know how to use the triangle to detect collisions of the triangle with objects but not have other objects detect collision with it. IE I dont want the field of view triangle to disturb the position of objects in the world. Im sure i will figure it out but any suggestions will be welcome.

I still currently stand with the issue i was having of placing the two points of the triangle in front of the player... I am missing something with the Newxvalue() functions and cant really see where I am messing up.

I want two points of the triangle 50units away from the front of the player and 1 point pointing at the player. It seems like a perfect solution to my problem as long as I can work out the collision issues. I would prefer to not turn the collision on and off if possible. Should I make the triangle a Limb or will this mess up my ability to change the way collision is detected because if i could do that it would avoid me having to alter its position every time the creature moves.
Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 29th Sep 2017 09:43

I haven't checked your code yet but will do asap

just a few comments:

- the 600 value for food and 300 for enemy is the sensing distance at which the square root distance check triggers action ( turn towards for food, turn away for enemy). It can be any value but remember that it is a vicinity value, it can't be too large.

- better to use the square root check to check distance for cycling through large amount of objects (faster) and use intersect object only once, when the object is close enough to trigger action. you could even avoid the square root calculation ( sqrt is fast but still requires computing time) and use the quadratic value check. So, for example, instead of having sqrt to return below <300 units you could check for <90000 (300x300) avoiding sqrt. (you do the math)

- Always use floats ( x#,y#,z#,tox#,toy#,toz#) with intersect object. (unless specified at the beginning of code as x as float, y as float etc..)

- intersect object if tweaked properly can cast a ray away from your object at any angle determined by the newxvalue etc. functions (angles appearing there can be increased by any fixed offset from 0 to 360), but usually it is used to cast from your object angle straight forward.

- if you want it to check a wider area around your target you can place a dummy cube conveniently larger then your target object at your target object location but below ground ( in order to make it not visible ) and check for that .
I'm not sure if intersect object still returns valid values even if the dummy target object is hidden ( hide object DBP command). if it does just place the dummy at your target object position, hide it and check for it.
i think its better to use one dummy for food and one for enemy only and move it around , but you could place a dummy at each food/enemy spot at the beginning and check for the dummy object instead with the for next operators ,
If you hard link the dummy object number to the food / enemy object number when creating the objects, then you know for instance that dummy 25 will correspond to food object 25-20 i.e. 5 and dummy 45 will correspond to enemy object 45-20 i.e. 25 : Just examples of course you choose the numbers at your convenience.

- try to avoid as much as possible built in DBP collisions, they are dramatically slow.

- all above is fine and dandy but you will get a performance hit beyond a certain number of characters in place.

- you said that you get 30ish fps with 500 m/f and 100 food and 100 enemy: what are your target numbers exactly? what are you PC specs ( cpu, ram, gpu, vram) ?


cheers
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 29th Sep 2017 16:16
Quote: "- better to use the square root check to check distance for cycling through large amount of objects (faster) and use intersect object only once, when the object is close enough to trigger action. you could even avoid the square root calculation ( sqrt is fast but still requires computing time) and use the quadratic value check. So, for example, instead of having sqrt to return below <300 units you could check for <90000 (300x300) avoiding sqrt. (you do the math)"


I would go further than this. Use a box check to eliminate out of range objects faster, then possibly follow up with a SQRT based check. Or possibly do away with using SQRT and just use a box check entirely. Odds are all you really need is a box check.

A box check is just comparing the X and Y values to see if the object is within a box area, which is much simpler and faster. For most purposes you can get away with just doing this.
If ABS(x1# - x2#) > 300 and ABS(y1# - y2#) > 300
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Sep 2017 21:21
Could you use the pick object commands to tell you which is the nearest object in the line of sight, etc? You wouldn't need any of the looping through the objects since that is presumably done, if at all, behind the scenes in an optimised manner.
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 29th Sep 2017 21:42
I would not presume so. You just need to test the speed by looping the command a thousand times and comparing the other method looped a thousand times. Make sure lots of objects are loaded.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Sep 2017 23:12 Edited at: 1st Oct 2017 00:38
Why do you need to loop the command? Use it just once to find the first object it hits. The Help file says this:

Quote: "PICK OBJECT
This command will return the Object Number of the closest object at the specified screen coordinates.
"


You just need to make sure the camera is facing in the right direction when you do the check. Use a separate camera if necessary.

Edit: Er, actually I don't think this works after all. I'd forgotten that the pick command responds to mouse clicks.
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 1st Oct 2017 00:16
I will explain. I was not talking about looping in the same sense you were. Since the command takes less than 1 ms, you cannot reliably time the command so you time 1000 of them and then time 1000 of the alternate method/command.

Now it is true that the Pick Object command does not require looping. However it is important to point out it almost certainly does the very same looping inside of the command itself. It has to check each object some way so it must. So this brings me to the point where I say it's better to load up a huge amount of objects and time each method x1000. This will definitively tell you which method is faster. As I mentioned this is an area where you can cheat. You can use a clever tactic to eliminate most of the objects in many cases. Such as using a box check.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Oct 2017 00:42
The timing issue is probably irrelevant because I'd forgotten an important feature of the pick object command - and it wasn't the main point of my original suggestion anyway. . I've edited my previous post.

I think I need a holiday.
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 1st Oct 2017 07:40
I have a huge 3rd person action game project that uses sparky's dll for hit scans and LOS. It allows for objects to be sorted into groups so the number of objects being checked can be organized and efficiently managed. I have stayed away from a lot of the built in commands.

Side comments:
I have this other game that relies on a lot of video animation, sprites, and 2D lines, boxes. I have noticed that advanced 2d plugin is much faster and better than the built in command. The DBPro sprite system is bad, like apparently for years people talked about it but never used it. If you change U/V coords then create another sprite then the U/V coords are reset on all sprites. This screws with my Bitmap font system.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 3rd Oct 2017 06:38
Ugg so, its been a hell of a past few days, But as luck would have it shortly after I posted my code, my entire computer crashed, had to reformat and everything... But atleast I posted my code here so I still have that

Pick object wouldn't work, that is an X,Y normally people use the Mouse positions to chose but I guess a different Camera... Might work but it would be slow as hell I would think even if it was going on behind the scenes.

I currently feel that using a triangle and having the one point at the creatures X,Y and the two other points would be the fastest way. I just can't seem to position it correctly and I do not know why. I would think it would just be something like this...
Rought example just to show the math but this does not work, It does not even work without the field of view to place a single point in front of the player. What am I doing wrong, something is totally flying over my head. It has something to do with the angles How Would I place a single object exactly say 100 paces in front of my object the angle its facing?



But if I make this detection cone and move it from creature to creature(or just included on the creature) I think it will be my best bet. I am attempting to learn sparky collision but I cant seem to get any of the functions to return a value and its had a habit of crashing my programs for seemingly no reason(sure there is one I just have not given it enough effort). Until I figure out the math I need I shouldnt waste time trying to learn something new. One thing at a time has always been my programming motto because I have made the mistake of changing to much at once before and destroyed damn near 60-100k lines of code which I still till this day have no idea what I changed that broke it.

Well its late and I am burnt, just got my computer working after like 3 or 4 days so I will try to respond better tomorrow.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 5th Oct 2017 21:16
Ok, so I incorporated the Triangle plane into my program and it works great.
I am currently moving the triangle around every time I move a creature but I may just give every creature its own sight plane. My FPS took a pretty big hit but the fact that I have much greater control over the creatures movements is something I anticipated and am ok with.
I currently have to turn off collisions with the creature that is "seeing" so that the triangle does not detect collision with it, turn on collision with the sight plane, move it and rotate it according to the creature so its in front of it, then check for collisions, act accordingly and turn off collision with the sight plane and turn back on the creature collision which I am sure is a huge burden on the processor.

I am not really sure how to tell where on the triangle the other object is colliding which is something I need to know. Is this where intersect object command comes into play? I need to know if its the left or right side of the triangle that the other objects are colliding with is. I am still new to DB so still trying to understand the abilities of each command.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 6th Oct 2017 04:41
Quick Demo I made to show how I currently using the triangle as a form of sight for the player.
Arrow keys control the player.

Im sure someone much more versed in this language will be able to suggest a faster means of performing these task, you can see how I have to turn the player collision off, then the sight on only to reverse this a few lines later to avoid detecting the object which is attempting to see in the first place.


What do ya'll think? I stripped it down to it's most basic components to show how I am doing it and to use this as a test program before fully adding the code to my other program.

What can I do to speed this up. Is there something I can do with limbs possibly because that is the next phase of my project anyway and I need to learn limb control since that is how my creatures are going to be built using a form of DNA that makes fractal type limbs ect. Ill explain that further in depth later down the line.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 6th Oct 2017 07:52
The raycast collision in Sparky's is better I think. It doesn't use a direction vector, its 2 locations but it should be faster. I've used it by taking the head location of the enemy and casting to a random bone on the player mesh... so if the player is only slightly visible it'll take longer for them to be spotted... kinda adds an organic realism but more importantly its accurate and only requires one ray cast check per enemy. I'd use Sparky's for any projectile collision checks as well.
The code is dark and full of errors
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 7th Oct 2017 06:42
I have been wanting to get my feet wet with Sparkys DLL but I have noticed crashes when toying with it that I don't fully understand and my #1 main issue I have with it is the commands are not returning values for me and I don't know why. I believe I have to set up my objects differently but to be honest I have not given it the full attention I need to as of yet.

I got a lot of work to do on other issues hence the reason I have not given the DLL the focus it needs to fully figure it out. I feel the Triangle method I am using is rather effective if I can just figure out how to tell where on the triangle the collision took place.


Question 1:
Can anyone tell me how to know where on the triangle the object hit? I really only need to know which side for the most part but an exact position would have its own benefits and I would rather know exactly where it hit.

Question 2: Is there a way of performing a collision test on the triangle without the triangle being detected by other objects? IE: I want the triangle to detect collisions but not have it be detected in the main section, I hope to do this without constantly turning collision detection on and off.
Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 7th Oct 2017 09:00
Sedit, it's not clear (to me) what you want to achieve by knowing the exact hit point on the triangle , despite my guess would be that by knowing where the hit point occurs you know what side of the character the enemy/food object is and you will manage rotations accordingly.

Not sure you have considered my last post since you didn't appear to react to that .

The code is yours and of course decisions are upon you but i would still consider placing a larger hidden cube or low poly cylinder at each enemy/food spot and check for that with intersect object once the square root (or quadratic value ) tells that you are at the proper distance range to trigger reaction.
I would totally avoid DBP native collisions and find some workaround.

Unfortunately I cannot run and test your code, my DBP throws a "cannot understand command at line..." error with any pasted code even though the line is empty.

Cheers
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 8th Oct 2017 08:43
Quote: "Sedit, it's not clear (to me) what you want to achieve by knowing the exact hit point on the triangle , despite my guess would be that by knowing where the hit point occurs you know what side of the character the enemy/food object is and you will manage rotations accordingly."


Right on the money Scorpyo. I figure that simple information will allow me to make all sorts of more complicated decisions on how to move the creature.

Quote: "
Not sure you have considered my last post since you didn't appear to react to that ."

I apologize, its been a hell of a past couple weeks here, between my computer completely crashing multiple times having to reformat and a Grandfather going in and recovering from heart surgery my focus is leaving alot to be desired to say the least. I have reviewed your response and read it multiple times I just failed to properly respond. I really like some of the ideas while some such as cycling through all objects every pass through the main loop or any other check I may need to perform. You really feel that using the sqrt instead of internal collision is faster? Even though I have to have the internal collisions on anyway to avoid objects passing through each other and have plans to convert it totally over to sparkys in time.

Sqrt is just telling me if the second creature is close enough correct, irrelevent of its orientation to the player(behind it etc). The issue I am having coming to terms with using such a method is cycling through every object is something I am trying to avoid since I might have upwards of 500-1000(maybe alot less but thats TBD after I put in the real characture control code) creatures at any given time. I did note however that I was able to run your code with much greater amount of objects (in the hundreds) while still retaining a decent frame rate which I found impressive.

Like I said I hope I didn't offend my making it look like I ignored your post, quite the opposite, I look at that code rather often but am currently still trying to totally dissect and understand exactly what is taking place.


Side note: When I try to make my creatures cones like you have done the fix object pivote command takes my frame rate down from 25 to 2.... any idea why that is?



Quote: " Always use floats ( x#,y#,z#,tox#,toy#,toz#) with intersect object. (unless specified at the beginning of code as x as float, y as float etc..)"

Yeah I have to get into the habit of properly labeling variables, I generally try to define any variable I use early on in the program since Im used to having to do so out of habit of using C++ back in the day but I catch myself slipping and has already resulted in some headaches here and there for me.

Quote: "Unfortunately I cannot run and test your code, my DBP throws a "cannot understand command at line..." error with any pasted code even though the line is empty."

Mine was doing this sometimes until I realized that sometimes it copy line numbers and since my DBPro already has line numbers it was reading the copied line numbers as something else so I have to delete them if I wish to use and copied code. My code looks like a chaotic mess at the moment with creatures darting all over the place and feeding so it be best to see how I am detecting using the triangle in this version of test code I made. I took out the line numbers so hopefully this will work for you.

Arrow keys control
Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 9th Oct 2017 14:12
Hi Sedit, no offense at all from your side, wasn't sure you had seen my post, since going through all your RL occurances might have easily happened.

A few points:

If you plan using Sparky's that can make things only go better about performance. I never used it therefore I don't know how it works. I suspect it uses collision detection by grouping objects and checking collision of those as a whole. In that case single object identity which you may need later on for tweaking may go lost. But I'm just badly speculating here.

Regarding the "pedantic and heavy duty" cycling many times through all objects, I don't see short cuts available here if you need to keep track of everything. One possible way is to do things in steps in the main loop like
if stepflag = 0 then gosub manage characters
if stepflag = 1 then gosub check enemy
if stepflag = 2 then gosub check food
etc..

Fix object pivot:
does not have an impact on frame rate at all if you don't use it , or use it sparingly, at run time.
That's for changing the default orientation of your object which may be rotated upwards, downwards or facing you or facing away from you and you need it reoriented . It's usually used for that task during setup when loading or creating objects which you may need to be rotated in another way (see the cone example).


Your code still doesn't work for me, but it's my DBP at fault , not your code.

I'm including 2 new versions of my first code.

The first one relies on a plane faking the view cone of the character, but at the target object position, which gets perpendicular to the character direction when a certain distance is reached and then intersect object checks distance. The small sphere is the pointing direction of the intersect function just to show the behaviour. in the real program it won't be there at all and the planes can be made invisible with "hide object" command.


The second one builds a check triangle ( fake, pure positions computing but no objects ) in front of the character (two additional small spheres and the character center make the triangle vertices) simulating the character field of view. This is tweakable at will of course, my choice was only for example sake.
It uses intersect object across the far vertices . As soon as an object is in the way the value becomes non-zero and triggers action. Not ideal because it only senses the front . For a complete triangle check we should cast rays from the character to the 2 front vertices also (ahead side spheres).
But I don't know if your characters will be somewhat driven by the player or it's just random movement.
This doesn't have a square root distance check (or quadratic value check) for vicinity. Most likely it will need to be reintroduced as the number of objects grow. The intersect object function is also very heavy duty, in some of my projects, where i need collision check for thousands of trees there is no way out other than to use it once for the closest object once detected with the square root distance.

I haven't included detection collision between characters, but basically it will go along the lines of, once again, cycling through them .

These are just sketchy proposals of approaches and will probably work only up to a certain object number.


All the best
Scorpyo

example 1



Example 2



Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 10th Oct 2017 04:03
Quote: "If you plan using Sparky's that can make things only go better about performance. I never used it therefore I don't know how it works. I suspect it uses collision detection by grouping objects and checking collision of those as a whole. In that case single object identity which you may need later on for tweaking may go lost. But I'm just badly speculating here."


I think down the line(if there is one for that matter but more on that in a little) the class structure that Sparky uses is going to be awesome because it will allow for me to only look for specific objects like enemy, mate or food depending on what the creature is searching for at the moment.


Quote: "Fix object pivot:
does not have an impact on frame rate at all if you don't use it , or use it sparingly, at run time.
That's for changing the default orientation of your object which may be rotated upwards, downwards or facing you or facing away from you and you need it reoriented . It's usually used for that task during setup when loading or creating objects which you may need to be rotated in another way (see the cone example).
"


I only used it in my Make_creature function which is only called at the start to initialize all the creatures and here and there whenever there is an available spot and someone breeds so its not like its constantly being called yet it DESTROYS my frame rate for some reason. I'm really curious about why this happens because logically in my head it shouldn't really make a difference since it seems essentially like nothing more then just an offset function for the objects angle. How this could slow down the rendering speed as much as it does confuses me.


Quote: "Your code still doesn't work for me, but it's my DBP at fault , not your code."

Not even that small little demo I made in the previous post? I'm curious because that's relatively simple and there isn't much to it. I know with the code you wrote I have to change the screen settings as the display mode don't work for me so I just comment out SET_DISPLAY_MODE at the very start and it worked fine. What error is coming up so I can get a better idea of the little nuiances that DBPro has to offer and give me more grey hairs.

Quote: "Regarding the "pedantic and heavy duty" cycling many times through all objects, I don't see short cuts available here if you need to keep track of everything. One possible way is to do things in steps in the main loop like
if stepflag = 0 then gosub manage characters
if stepflag = 1 then gosub check enemy
if stepflag = 2 then gosub check food"


Well using the internal collision testing with OBJECT_COLLISION(Creature_number,0) the flag set to zero pretty much covers the cycling through all objects internally. Im sure in the compiled machine code that pretty much what that does because idk how else it would do it other then checking my object against all other objects.

The way I have it setup in my code I can't really make a check for enemy because enemy and creatures are the same thing, Its just if it sees a creature and its Sex is the same as the creature it sees it as an enemy and reacts. Right now I just have it lose health and run away but as it get more complicated its going to decide weather or not to attack or run in a rudimentury Fight or Flight mechanism.

Your SQRT checker is going to come in very handy down the line because right now the currently remeber the last place the EAT, BREED, and FIGHT. It is a very specific point in space but thats not totally helpful because if they ate the food at the last place or if the enemy is still sort of around the last place they fought a specific point in space is no good. I rather them go back to last place the found food and sort of look around that general area for more.


==============================================================================================================================================================


Sadly.... All of this may not matter at all until I figure something out because I am poor with 3 kids and can't afford a new computer to save my life and mine just completely and totally crashed again today. This time even the Recovery partition is now corrupt so there is just no way to fix it this time. It does not even see my hard drive as existing so not only is all my recent work totally gone which sucks but I no longer have a computer to program on in the first place. I'm sending you this message off of a computer that is around 15 years old almost and just not capable of using to Develop programs. I only got it out of storage to attempt to fix the other one by having internet connection....

But its dead, totally dead and I'm so utterly depressed about it I couldn't even begin to express how stressed I am. My computer is my entertainment system, Its my TV, Stereo, Game system, Internet, hell I use it for a phone most the time now also. I live on my computer and now I have absolutely nothing at all to do, I cant even run the code you just posted and play with that but worst of all I can no longer continue teaching my kids coding which is what started all of this in the first place.....

:sigh: Oh well I guess such is life. Something will work itself out I guess.. i hope.. but as of now this project is on hold indefinitely.
Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 10th Oct 2017 10:30 Edited at: 10th Oct 2017 10:32
Man, that sucks big time,
But nothing might be lost yet.
First of all I would pull out the HD from the not working PC and put it into the old one as a second HD and just check if it gets seen/recognized. Then, if you got lucky, find an HD analysis and repair tool from the internet and see what's going on and what you can do.
I guess your system has an OEM version of Windows tied to the Mobo serial. Usually when you start the machine they give you an option to burn a recovery DVD. Do you have it?. If not the manufacturer should be be able to provide you a copy for few dollars or for free via download. If so you save it to a Pendrive and try to restore it in the HD, provided the HD recovery was successful.
Else you may buy a used or new HD for cheap and buy a Windows license . Still much cheaper than buying a new PC.
On Ebay they sell used HDs with Windows installed for cheap (30 - 50 dollars) but this is not advisble because most probably Windows will ask for a valid license key being the HD been transferred to a different machine. Not sure what to say here. It Needs a lot of research.
Maybe one can find a used HD with Windows preinstalled including a valid license.

Additionally:
Is you bios battery full charge?
Is your Mobo bios uncorrupted?
Are your inside connectors / RAM sticks not oxidized ?
Are you confident in PC assembly / disassembly? Is so I would pull everything apart and reassemble it, ( don't blame me if you fail, lol)

Just a few ideas for temporary solutions
More versed people on the forum may be so kind to comment and give advice.
Cheers
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 10th Oct 2017 22:02
Yeah i tried to make the recovery disk but the C: and D: drive are both corrupt, D: being the recovery partition, I know what the problem is, the sectors are gradually going bad and last time it crashed like a dumbass i never fully did what I should have and make sure the computer ignores the bad sectors, as a result I now have a computer that can even detect that the C: drive even exist. I just have the Boot X: drive but that just contains system stuff. I am great at taking stuff apart so I am going to rip into it a little later because my family is bringing me a spare harddrive to use and we are going to see if we can get that running and maybe setup the old one as a slave or something.

Dunno, what is the MoBo Bios and how can I find it?
Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 10th Oct 2017 22:31 Edited at: 10th Oct 2017 22:33
If you are sure it's a faulty Hard Drive stick to that option first and forget the rest. Still it would be worth putting it into another machine as a second HD and check it out.
If you don't know what Bios is, you better forget about it ( it's a kind of a simple OS for the motherboard that detects all hardware present in the machine ( Hard Drives, Optical Drives, RAM, CPU etc...) at boot time. It is very dangeruos to delve into it if you don't know what you're doing , you can trash the Mobo to no possible recovery forever . (MoBo stands for Motherboard)
But just for info you can visit some internet sites that explain it's function.

I wish you the best to be up and running again.

Cheers
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 11th Oct 2017 23:31
oh yeah i know what a BIOS is I just never heard the Mother board Bios called Mobo is all. Still waiting on that hard drive from the family but i have a feeling I will be waiting for sometime for that to be honest.
Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 12th Oct 2017 07:28
Actually "Mobo" is the short term sometimes used in place of "motherboard " .
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 13th Oct 2017 05:17
Scorpyo, does your DB allow for #constant? I just got a new one that will not compile my code until i eliminate the word #constant from the code.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 14th Oct 2017 09:09 Edited at: 14th Oct 2017 09:10
Hey all, This should get me what I need to know as far as where the collision occured correct? Or atleast a close approximation as it should tell me if its on the left or the right of the creature right?

These commands tell me the center of the object he is seeing so I should be able to tell if its to the left or right rather easy.
OBJECT COLLISION CENTER X
OBJECT COLLISION CENTER y
OBJECT COLLISION CENTER z


Due to the fact this old ass computer I pulled out to fix my laptop has almost no ram and Chrome takes 70-95% of my ram just running it I am going to focus what I am working on in my program a little more. I think I am going to attempt to perfect the AI which is going to be a small Neural network that runs through supervised learning by allowing the user to control one of the creatures and your reactions to various things seen are going to basically be recorded into the Neural Network and translated to all the creatures after that. So say for instance you want to kill your creatures you would run them into danger but Good luck because due to the nature of Neural networks and my Fitness function its going to resist your attempts to kill it as that would lower its score. Im going to attempt to make my NN as small as possible with maybe 3 inputs(enemy, mate,food) and 5 hidden layers (enough to vary the network)and 2 outputs(turn towards or away) This should run rather smooth as long as the trainer is the player because my over all goals of this game are something I am about to talk about in another thread very soon.

Many may say, NN in DBPro, Impossible.... Impractical etc etc... well you may be half right. If however I find out that performing all the calculations starts to become a burden in reality I don't need 500 NN running if I have 500, All I really need is the one being trained by the user and a good spread across the population. After that the network could be essentially hardwired for the other creatures so something along the lines of maybe 1 out of 10 of the Alpha males learn and the beta males follow suit. This is just a worst case situation if I cant perform all the calculations needed by I am sure its going to be a more then effective Plan B
Ignatura
7
Years of Service
User Offline
Joined: 20th Sep 2016
Location:
Posted: 17th Oct 2017 05:35
if its about getting characters to look and move in the direction of the camera use atanfull
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 17th Oct 2017 06:05
Na its about getting them to see in their virtual world and react to what they see in front of them. If they see an enemy turn or run away if its food or mate head for it etc...

After coding all day I finally finished making my creatures smart and I couldn't be more excited right now. Its the most bloated and piece of shit code I think I have ever written because I changed my entire methodology like 5 time and had to adjust the code to fit so this mess is 550 lines of code right now when it could prob be done in 50 BUT!!!!!

IT WORKS!!! I now have a working Neural network of my own design that functions correctly. It takes my input and causes the creatures to react to their surroundings exactly how I did when I had the controls...

Training Function
Supervised learning:
I play as a single creature to start off with, This records the keys I am pressing and the over all % of time I am using those keys while the creature is looking at whatever its looking at. Then I turn those controls over to a few hundred creatures and off they go reacting exactly how I asked them to. If say 40% of the time I went towards a mate and 20% of the time I ran away from an enemy, they will do exactly that.

Im sure a normal Neural network would work better and I MANY improvements to make on my system but given that its something I top to bottom Engineered without having to learn anyones math or copy anyone elses code and now have a creature that thinks is the greatest feeling in the world.

I am going to clean up this mess and see if I can get it to around 100 lines of code before I continue on to my Genetic Algorithm which is where the real power comes in because only the best creature will survive and in no time I will have a truly intelligent creature
Ignatura
7
Years of Service
User Offline
Joined: 20th Sep 2016
Location:
Posted: 21st Oct 2017 10:27
Sedit wrote: " If say 40% of the time I went towards a mate and 20% of the time I ran away from an enemy, they will do exactly that."


emulating what the player does how are they going to learn what's valuable specifically to themselves? in the real world we react to things by our self and gain stats.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 21st Oct 2017 20:44
Mutation rate, altering the Values of the Weights by a percent or two every time a new creature is made causes the one most fit to produce offspring to be the one that passes its genes.
Also the new creature is the average of the mother and fathers Weights so if you randomize it all at the start the offspring will have an average of its parents +- mutation_rate.

Something like this to add or subtract by a random amount between the Mutation rate
weight = weight + (Mutationrate - RND(mutationrate * 2))


Im working on the UI Right now and am almost done its most basic form but it adjust every generation slightly altering the weights one way or another due to a mutation rate I put in. Normally by a percent or two, those that live the longest breed the longest just like in real life and you can rather quickly see the weights change in favor of what benefits the little creature. For instance, you generally see going forward for food and mate become the highest number and going backwards when they see a mate yet if their speed happened to turn into a Negative number due to the same mutations the number going towards an enemy goes up and those going away from food and mate goes up because they move MOVE OBJECT creature.speed so if its a negative number they go forward when suppose to be going backwards etc. Its funny because early on the Speed generally goes + or - and once its far into the negative there is no changing it because if a creature tries to turn the speed into a positive after the weights are already set up it does everything wrong and can not live long enough to breed into the next generation.

Its similar to a Fitness function in normal Artificial Neural networks with genetic Algorithms except its built into the mechanics that the weights to the network which benefit the creature are propagated more often.

Each off-springs weights are the average of their parents and even though the whole system starts off random (or 20% across the board) they quickly lean one way or another. Funny part is I am having trouble getting them to really care about eating almost every time leaning more towards having a huge birthrate instead of. They start off seeming to like going towards food but after an hour or so they find another way and tend to migrate away from the starting area.



Im hoping to have it be user friendly by the end of tonight or tomorrow so keep checking back and I will have it uploaded here.

Login to post a reply

Server time is: 2024-04-25 16:43:26
Your offset time is: 2024-04-25 16:43:26