GalaxySugar Posted July 30, 2021 Share Posted July 30, 2021 (edited) I'm working on a mod where a specifc character can get a position from the map and teleport to that position, this works, but they can teleport into ocean void past the waterfalls and cave void. Currently using this to check if the position. local tile = GLOBAL.TheWorld.Map:GetTileAtPoint(self.minimap:MapPosToWorldPos(x, y, z)) if tile == GLOBAL.GROUND.IMPASSABLE or tile == GLOBAL.GROUND.INVALID then print("Can't go there!") return end and it barely works... The character can still teleport if the ocean void is on the Northwest or Southeast sides on the surface along with random spots in the cave void. Any way to fix this? Edited July 30, 2021 by GalaxySugar originally posted when tired. Link to comment Share on other sites More sharing options...
Monti18 Posted July 30, 2021 Share Posted July 30, 2021 If you only need a walkable position, use FindWalkableOffset: function FindWalkableOffset(position, start_angle, radius, attempts, check_los, ignore_walls, customcheckfn, allow_water, allow_boats) return FindValidPositionByFan(start_angle, radius, attempts, function(offset) local x = position.x + offset.x local y = position.y + offset.y local z = position.z + offset.z return (TheWorld.Map:IsAboveGroundAtPoint(x, y, z, allow_water) or (allow_boats and TheWorld.Map:GetPlatformAtPoint(x,z) ~= nil)) and (not check_los or TheWorld.Pathfinder:IsClear( position.x, position.y, position.z, x, y, z, { ignorewalls = ignore_walls ~= false, ignorecreep = true, allowocean = allow_water })) and (customcheckfn == nil or customcheckfn(Vector3(x, y, z))) end) end Example of usage: local pos = inst:GetPosition() local offset = FindWalkableOffset(pos, math.random() * 360 * math.pi, math.random(400, 800), 500) local treasure = SpawnPrefab("treasurechest") if offset then local spawn_pos = pos + offset treasure.Transform:SetPosition(spawn_pos:Get()) end This finds a random position in a distance between 400 and 800 in a random direction from the player and spawns a chest at that point. The position is then declared by adding the offset to the initial position, as this is only an offset from the position you start from. 1 Link to comment Share on other sites More sharing options...
GalaxySugar Posted July 30, 2021 Author Share Posted July 30, 2021 edited the original post, I was super tired when I made it. I can already teleport the character where I want it to, I just need it to refuse to teleport there if its out of bounds. Link to comment Share on other sites More sharing options...
Monti18 Posted July 30, 2021 Share Posted July 30, 2021 I understood you correctly, this was just an example of the usage If you have the position you want to teleport to, enter it in findwalkableoffset as pos. Then as radius I would enter 1 or 2,these should be good. As attempts I would use around 50 or so, more should not be needed. You will then get the offset that is walkable, add it to the position you want to teleport to and you're done 1 Link to comment Share on other sites More sharing options...
GalaxySugar Posted July 30, 2021 Author Share Posted July 30, 2021 (edited) Edit : Completely misunderstood what FindWalkableOffset did. Using it still results in the player still able to teleport past the waterfalls on the northwest and southeast sides of the ocean, so it's not really any better than what I was using before... Edited July 30, 2021 by GalaxySugar Link to comment Share on other sites More sharing options...
Monti18 Posted July 30, 2021 Share Posted July 30, 2021 (edited) So you want to be sure if the exact position you have is walkable, but it still teleports you in the outer bounds of the map. You could use local tile = GLOBAL.TheWorld.Map:GetTileAtPoint(self.minimap:MapPosToWorldPos(x, y, z)) print("tile",tile) if tile == GLOBAL.GROUND.IMPASSABLE or tile == GLOBAL.GROUND.INVALID then print("Can't go there!") return end local walkable = FindWalkableOffset(pos, 0, 0, 1) if walkable == nil then print("not walkable") return end to see if this is a walkable point and see if that works. Otherwise if it still happens, print the tile to see which one the game says it is. Because then the game thinks that this is not impassibl, but this should be impassible Edited July 30, 2021 by Monti18 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now