Jump to content
M0lD

GetPosition of an Entity

Recommended Posts

So i have an Pivot in the map,
image.thumb.png.a4ef73808643799ac252da223ed6b1c2.png

And in an C++ Class i need to know where that entity is, and its position...
image.png.0550868522d0b26f37fc393afa387255.png

Share this post


Link to post

I believe you have to loop over the world->entities and call ent = world:GetChild(index) and look for the name (ent:GetEntityValue("name") ?) and then you have the entity in which you can call GetPosition() on. Honestly, it would be nice if there was a handy dandy function(s) for this kind of stuff. The function would return a list (since names can be the same). Maybe even be able to tag entities with some kind of value in the editor and find all entities with that tag.

  • Like 1

Share this post


Link to post
9 hours ago, Rick said:

Honestly, it would be nice if there was a handy dandy function(s) for this kind of stuff. The function would return a list (since names can be the same). 

This is something I have always found kinda odd when working with C++. I would have this massive switch/case list to get certain entities from my scene. Somehow that feels clunky. But even if there were an official function for this, it would probably do something similar in the background.

Share this post


Link to post
6 hours ago, AggrorJorn said:

This is something I have always found kinda odd when working with C++. I would have this massive switch/case list to get certain entities from my scene. Somehow that feels clunky. But even if there were an official function for this, it would probably do something similar in the background.

One way to do this ourselves (but still would be nice if this was part of the engine), is to loop over all the world->entities and get their names and store them in a map<string, vector<Entity*>>. Now we have a dictionary where the key is the name and each entity is in the list for the key that matches it's name (since entities can have the same name). Then we can just access the entities by name like: entiites["MyPivot"][0] if you know there is only 1 with that name.

What was the case statement for? It's been awhile so I don't recall. Was it for each different type and you cast or something?

Share this post


Link to post

I dont need to loop it overcand over if i only need it ween the map starts, im just makeing the camera, in C++ And set its location to an pivot...

Share this post


Link to post

Yeah, I'm saying you would loop over world->entities once and add them to the map of lists with the name as the key and then you can get it via name which isn't a straight loop again, but the idea is today you just need the pivot but tomorrow you need another pivot, then the lights, then etc etc.

  • Like 1

Share this post


Link to post
22 hours ago, Rick said:

I believe you have to loop over the world->entities and call ent = world:GetChild(index) and look for the name (ent:GetEntityValue("name") ?) and then you have the entity in which you can call GetPosition() on. Honestly, it would be nice if there was a handy dandy function(s) for this kind of stuff. The function would return a list (since names can be the same). Maybe even be able to tag entities with some kind of value in the editor and find all entities with that tag.

I dont find world.GetChild()...

image.png.beaa1a7676ef603520c750df70ac7545.png

Share this post


Link to post
foreach(auto e in world->entities)
{
  if(e->GetKeyValue("name") == "player")
  {
  }
}

 

It's been awhile since I've worked on the C++ side of things, or in LE really. Above I believe is the way to loop over entities in the world after the map is loaded. Sorry, no GetChild() needed I guess.

 

Might be more like the below. Sorry, like I said been awhile :)

 

for(auto e : world->entities)
{

}
  • Like 1

Share this post


Link to post

The documentation is pretty much gone now becuse of Leadweks 5? Becuse the "Old documentation" links are talking if stuff thats gone now." (I found out leadwerks had an forum long after i started useing it) 

Haveing everything documented and enableing users to add examples like comments would make a lot of the currently active questions non-existant...

Share this post


Link to post
18 minutes ago, M0lD said:

The documentation is pretty much gone now becuse of Leadweks 5? Becuse the "Old documentation" links are talking if stuff thats gone now." (I found out leadwerks had an forum long after i started useing it) 

Haveing everything documented and enableing users to add examples like comments would make a lot of the currently active questions non-existant...

No. All the documentation found here: https://www.leadwerks.com/learn?page= is part of Leadwerks 4.x . It is just a new documentation system which was filled from scratch. So some information in the old documentation website might not be written in the new documentation system.

Adding comments to pages would be nice, but for now we would have to file a bug report. Things get fixed very quickly if described properly. Example.

 

 

 

Share this post


Link to post
2 minutes ago, AggrorJorn said:

No. All the documentation found here: https://www.leadwerks.com/learn?page= is part of Leadwerks 4.x . It is just a new documentation system which was filled from scratch. 

Adding comments to pages would be nice, but for now we would have to file a bug report. Things get fixed very quickly if described properly. Example.

 

 

 

But the current 4.x documentation is missing much

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...