Jump to content

Using FindEntity to get Coordinates?


Recommended Posts

I need to detect the x,y,z coordinates of a boat that a player is jumping onto.  'FindEntity' seems like the way to go, but I'm not very familiar with this function.

The Crab King used this code, but I've been having a tough time adapting it to my needs, and I'd prefer to simply understand the function.

local boatents = TheSim:FindEntities(x,y,z, 25, BOAT_TAG)

I've searched the forums for answers, but the posts I found were around six years old and weren't able to help me.

Link to comment
Share on other sites

FindEntities(x, y, z, radius, musthavetags, nottags, hasoneoftags)

Returns a ordered list of ents from closest to furtherest of x, y, z that is within radius and has & doesn't have & has one of those tags.

Musthavetags is a table of tags the ents must have them all.

Nottags is a table of tags the ent cannot have to be valid.

Musthaveoneoftags is table of tags where the ent only needs 1 of to be valid.

Edit:

For more information look up FindEntity and FindEntities in simutil.lua

Edited by IronHunter
File is simutil.lua
  • Like 3
Link to comment
Share on other sites

@IronHunter
That certainly helps explain why it wasn't working.  All I wanted was the nearest entity to a point, not a list of entities..  There's a 'FindClosest' under Behaviors but I haven't tried using that yet; doubt it'll work though.

I've looked through entityscript.lua and none of these functions appear to do what I need. FindEntity/FindEntities do not appear to be in this file either.

My reason for this search is that I'm trying to improve my character's swimming code, and I have a sneaking suspicion that the code for jumping onto a boat is having the player land on the edge of the boat, and I want to try making them land closer to the boat's center to see if that helps improve stability.  It's the only part of the mod that's reliably, iffy, and I want to fix it.

Link to comment
Share on other sites

@IronHunter
Wonderful, thank you.  I've poked through that file and wrote this code:

local testboat = GetClosestInstWithTag("boat", inst, 20)
if testboat and testboat:IsValid() then
	print("Test for Boat 1: ", Vector3(testboat.Transform:GetWorldPosition() ) )
	local boat_x, boat_y, boat_z = testboat.Transform:GetWorldPosition()
	print("Test for Boat X: ", boat_x)
	print("Test for Boat Y: ", boat_y)
	print("Test for Boat Z: ", boat_z)
	--return Vector3(testboat.Transform:GetWorldPosition() )  --Note: Causes some sort of looping error.
end

 

Edited by FurryEskimo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...