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 / Ray tracing to detect objects with mouse interfers with ray tracing from objects for pathfinding / object avoidance from that object / enemy ??

Author
Message
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 8th Dec 2018 21:46
I've got a curious problem that maybe others have run into... but I'm using some code to detect which object was clicked on. This works fine.

However, it uses ObjectRayCast like this ;



In the movement code of enemies I'm using the following code, also using Objectraycast ;




Despite explicitly calling one 'sense' as a local variable and another 'object_hit' , they still interfere and return object IDs it really should not.


Any strategies on how to explicitly avoid this?? The problem is, both the mouse clicking and the object detecting involves the same 'enemies' entities. But a mouse click should never be used for an object ID detection during movement or you get some really weird behavior (for example, clicking an enemy now makes all enemies stop, because ray tracing has found an object with a mouse click).


Is it somehow possible to get the index of a ray trace from the mouse click and always ignore that index somehow for when movement does a ray trace check to see if it is bumping into another enemy entity?
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 9th Dec 2018 04:31
Maybe if you traverse the hit table (Get3DPhysicsRayCastNumHits(), GetObjectRayCastHitID()). It might clear out alll the contact information for each ray
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 9th Dec 2018 11:17 Edited at: 9th Dec 2018 11:19
Thanks! Yeah, with over 1000 critters moving around, it is not really an option to do a trace check with specific object IDs, where the ID would be known. (I guess?) I'm a bit puzzled how to clear the contact information.
Maybe it saves it longer because I check both the first index and second when more than one hit was detected for an enemy object.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 9th Dec 2018 19:03
So you think it's a bug? Can you give me a specific instance?
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 10th Dec 2018 14:35
Quote: "So you think it's a bug? Can you give me a specific instance?"


Well, it might very well be, because it seems these ray tracing returns (both the amount of hits and object hit IDs) do not seem to remain 'local' variables, but instead are global and overwrite ray traces in other functions.
Even weirder is that I am sometimes getting invalid object ID identifiers back, like 3460346345963211 instead of something like 100006 or 100453 .

I have to see if I can make a short example that shows the issue.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 10th Dec 2018 20:44
I recommend you set #option_explicit
It will force you to define any undefined variables but will certainly remove any scope issues
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 16th Jan 2019 00:14
Thanks! That may be a very good idea actually.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 16th Jan 2019 05:24 Edited at: 16th Jan 2019 05:25
So I ran into a similar issue with Sparky's Collision plugin in dbpro, which was also written by Paul and which has a very similar command set to the AppGameKit raycast command set, so I think it's a fair guess that these may be based on that same code base.

In my dbpro project using sparky's, casts by the AI for detecting characters by sight would interfere with casts by the player for environment collision. Scoping was definitely not the issue in that case, something seemed to hang around in the raycast's internal results. To resolve this, before beginning my environment casts, I started "grounding" a cast straight down to clear out any previous hit result and this seemed to take care of things.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 16th Jan 2019 14:02
That's very interesting! So how do you set up such a 'reset trace' ? Just any position will do and do a trace that's unused?
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 18th Jan 2019 23:50
@blink0k : It's perhaps a bit of a newbie question, but how should variables be declared using the #option_explicit tag when they are 'local' variables used by a function that is running dozens if not hundreds of times? In other words, what do I do to declare them, without making them 'global'?


ie. I use local variables to decide an object's behavior based on distance, such a distance variable is often just a d# or something. But I don't think that should become a global d# or I risk changing its behavior.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Jan 2019 01:54
All #option_explicit does is throw an error if you use a variable that is not defined
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 19th Jan 2019 01:55
Quote: "That's very interesting! So how do you set up such a 'reset trace' ? Just any position will do and do a trace that's unused?"


I was just firing straight down from a little over the character's head to the ground

Quote: "ie. I use local variables to decide an object's behavior based on distance, such a distance variable is often just a d# or something. But I don't think that should become a global d# or I risk changing its behavior."


You can just do d as float in the function
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 19th Jan 2019 02:06
have you tried only raycasting the area of the object


you will need to check that it isnt just detectingt the object passed
fubar
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 19th Jan 2019 11:26
Hi there.
What about instead of using raycasting, use GetScreenXFrom3D /GetScreenYFrom3D to detect what object has being clicked ? something like this :

I'm not a grumpy grandpa
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 19th Jan 2019 14:29
Thanks Ortu, it's worth a shot. Thanks for the other helpful suggestions as well guys.

Interesting Chafari , that definitely sounds like a work-around, should all fail still.

Login to post a reply

Server time is: 2024-04-19 09:40:19
Your offset time is: 2024-04-19 09:40:19