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 / Get ObjectID

Author
Message
Olde Worlde Illusions
3
Years of Service
User Offline
Joined: 10th Oct 2021
Location:
Posted: 4th Dec 2021 05:25 Edited at: 4th Dec 2021 05:26
How would I get the ID of the object if I knew its coordinates? I checked the help documentation but there isn't a

function. Does anyone have any ideas?
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 4th Dec 2021 05:56 Edited at: 4th Dec 2021 05:58
when you are making the object,

make sprite or load object

What I do is

Thisplayer=whateveryouloaded

so lets say im making a sprite

for x=1 to 100
mysprite=createsprite(0)
thisspritenumber=x
inc x
inc thisspritenumber
next x

print(thisspritenumber)
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 4th Dec 2021 10:39
As GCH said you should really be keeping track of your object ID's but I can see cases where you need the id from position...

For this... cast a ray to the object location, the ray hits it and returns an id

first pick a median point to start, I say go a few units above the object and cast the ray down, viola, you have the id returned from ObjectRayCast

Something like this should work, you may need to play with the distance according to your object sizes

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Olde Worlde Illusions
3
Years of Service
User Offline
Joined: 10th Oct 2021
Location:
Posted: 4th Dec 2021 19:41
I am keeping track of my object id's:

The issue is i can't simply say tell me the id of the object at x, y, z...
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 4th Dec 2021 20:31 Edited at: 4th Dec 2021 20:32
Ok ok ok, no need to get "Defensive" lol [For clarification, that was a joke!]

Quote: "tell me the id of the object at x, y, z"


Things like this are what RayCasting was built for.. ... try my simple function
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 4th Dec 2021 20:35 Edited at: 4th Dec 2021 20:42
It may be that the objects center point is not within the mesh so you might want to use GetObjectMaxX/Y/Z() GetObjectMinX/Y/Z() to calculate the center of the object.
Also it might be a good idea to check each axis. I think the example might not work if the shape was a doughnut
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 4th Dec 2021 20:48 Edited at: 4th Dec 2021 20:51
It would not matter on the objects origin as it will register a hit on the mesh geometry not the origin point, but a doughnut, yes it would fail from above, cage it and check all axis + and -, the Min/Max functions would help there too.

Edit: Actually, the Min/Max are still no good as we don't yet know the object id, distance will have to suffice.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 4th Dec 2021 20:54
You say you know it's coordinates, so you could just loop through your array of objects and return the ID of the one with coordinates that match what you are looking for.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 4th Dec 2021 21:02
But that would rely on the origin point being at that location ...

something like this should work
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 4th Dec 2021 21:04
Quote: "But that would rely on the origin point being at that location ..."

It would, but that's how I read the question
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 4th Dec 2021 21:12
Well I guess it depends on interpretation, I was taking it as the object is dynamic, a static object sure just loop the array as it will be where you placed its but if its on the move and its 1 unit out on either axis, its a fail.

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 4th Dec 2021 21:14
Another solution would to be place a hidden object at the location and check for a collision and get the ID that way, personally I'd go with ray casting
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 4th Dec 2021 21:21
Quote: "It would not matter on the objects origin as it will register a hit on the mesh geometry not the origin point, but a doughnut, yes it would fail from above, cage it and check all axis + and -, the Min/Max functions would help there too.

Edit: Actually, the Min/Max are still no good as we don't yet know the object id, distance will have to suffice."

Yes you are correct. I don't know what i was thinking
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 4th Dec 2021 21:39 Edited at: 4th Dec 2021 21:39
Well you had a good point about the doughnut, and made me hungry thinking about them! lol

Thought I'd better check my air code, indeed it works
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee

Login to post a reply

Server time is: 2024-11-21 12:26:24
Your offset time is: 2024-11-21 12:26:24