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.

Newcomers AppGameKit Corner / How can I pick up a mesh?

Author
Message
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 1st Oct 2017 21:23
Let's say I have a building with some doors. How can I determine which one I try to open? Or which medikit I want to use?
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 1st Oct 2017 21:54 Edited at: 1st Oct 2017 21:57
Use a 'Type' with a object id and a name, when you raycast an object send its id to a function to get its name, now you know what door/health pack you are using



or using the .find function

janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 3rd Oct 2017 02:57
Or if you just want to know the object ID you can detect it with a ray cast or object collision
GetObjectRayCastHitID
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 3rd Oct 2017 22:00 Edited at: 3rd Oct 2017 22:04
Thanks, I'll try them.
hoyoyo80
8
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 4th Oct 2017 01:47
@Janbo, how do i use the id that i fetch later on...i think i ever tried but it return 10k(?) value to me but it dont mean anything to me..

Thanks
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 4th Oct 2017 18:04 Edited at: 4th Oct 2017 18:05
First you need to cast a ray then you could retrieve the object id of the first hit with GetObjectRayCastHitID(0)
The 10k value is probably the object id if you create objects with the overloaded function.
There are two ways to call the an object creation command as you probably know:

Here you need to set the object id
and

Here AppGameKit will generate an object id for you which starts at 10k
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 4th Oct 2017 19:15 Edited at: 4th Oct 2017 19:16
Quote: "how do i use the id that i fetch later on...i think i ever tried but it return 10k(?) value to me but it dont mean anything to me.."


Create your object in a type and give it a name like I showed you above, get the object (10k) id from the ray cast function and send it to the GetItemName

a more complete example
hoyoyo80
8
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 4th Oct 2017 23:36
Wow!...Thanks, now i got it
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 1st Nov 2017 10:42 Edited at: 1st Nov 2017 10:43
Sorry, it doesn't work I probably didn't ask the right question, so I made a short video since one picture is worth 1000 words as they say sorry for my poor English
[video=youtube]https://youtu.be/jyEM2_b8YJM[/video]
How can I check which door I am looking at? GetObjectRayCastHitID(0) works only when I hit my face against door and only in the very moment I hit the door, no chance to press space or any other key in the right time to open the door.
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 2nd Nov 2017 22:08 Edited at: 2nd Nov 2017 22:16
1. You post youtube videos like so: [video=youtube] jyEM2_b8YJM [/video] (but without the spaces)


2. It looks like you cast a ray from the camera to a certain distance in camera view direction.
You will need: ObjectRayCast
ObjectRayCast( objID, oldx, oldy, oldz, newx, newy, newz ) <- you want to check every object so objID will be 0
Then oldx/y/z will be the camera position (GetCameraX /Y/Z)
And finally newx/y/z will be a position in front of the camera...you can get this position easily if you use a neat trick:
You move the camera forward a certain distance (MoveCameraLocalZ)
Then grab the camera position (GetCameraX /Y/Z)
And then move the camera back to the old position like nothing ever happened (MoveCameraLocalZ just with the negative distance)

[offtopic]
In your code example:
Does the command cast an infinite ray ? i.e where ends the raycast ? as there is no parameter in the command you are using
does that also mean you can open doors from 100 meter away ??
[/offtopic]
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 4th Nov 2017 00:20
1. Thanks, I'll remember
2. Looks complicated, but thanks, I'll try.
Offtopic: If I comment lines checking distance - looks like yes And it's a command definitely worth implementing in AGK2. Imagine we're not talking about a static door, but about shooting at a zombie a bit further (we don't know how far) - jump camera forward until it hits something? What step? Definitely looks complicated and looks like serious slowdown...
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 4th Nov 2017 15:16 Edited at: 4th Nov 2017 15:35
Quote: "Definitely looks complicated and looks like serious slowdown"

Hm I think it looks more complicated than it really is.
Also if the ObjectRayCast command is fast the rest is for sure.
Grabbing the camera position and moving it forward and backwards is sooooooo fast.. (internally: it's doing a translation of the view matrix which is a matrix multiplication with a vector)
You can further optimize the raycast by checking for single objects only, not all of them.
If I would make an Engine in C++ with OpenGL I would do it pretty much the same way.
I think the IrrGetCollision*** command is pretty much the same but in an other skin.

There are many ways to achieve what you need.
If you like the syntax from irrlicht then just make something like this...
It returns the ID of the hit object
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 10th Nov 2017 13:35
Thanks very much, it works with every purpose I want But I still insist to include it into the AppGameKit command set. The piece of code above shows your mastery in coding and deep knowledge of AppGameKit commands, but AFAIK AppGameKit isn't for masters of coding like you, but for eternal beginners like me and it's a very basic command that will be used with opening doors, picking up objects, shooting at zombies etc., so - I'll say it again - I hope to see it in the next update of AGK.

Login to post a reply

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