. . . Posted July 12, 2017 Share Posted July 12, 2017 (edited) Hello, I was wondering is there a code where I can check the height of an entity? Cause I'm trying to make some jump action for my character & it would be very tedious to do a check for every single prefab I don't want my character to jump over.. Thanks for reading my question, & have a great day/night ! Edited July 15, 2017 by SuperDavid Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/ Share on other sites More sharing options...
ZupaleX Posted July 13, 2017 Share Posted July 13, 2017 Each entity which is "solid" (cannot be passed through) have a sphere to simulate the collision. You could check the radius of that sphere. Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-938892 Share on other sites More sharing options...
. . . Posted July 13, 2017 Author Share Posted July 13, 2017 Do you know what line of code I can use to check it ? Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-938981 Share on other sites More sharing options...
ZupaleX Posted July 13, 2017 Share Posted July 13, 2017 (edited) I have to admit I did not touch DST modding in a really long time (more than a year ago) so from what I remember in the instanciation you have a MakePhysics(x) or something along these lines where x is the radius of that sphere. You have to figure out which property holds it. A component should have this info somewhere. EDIT: I checked it out quickly, the real function is for instance function MakeObstaclePhysics(inst, rad, height) inst:AddTag("blocker") local phys = inst.entity:AddPhysics() phys:SetMass(0) --Bullet wants 0 mass for static objects phys:SetCollisionGroup(COLLISION.OBSTACLES) phys:ClearCollisionMask() phys:CollidesWith(COLLISION.ITEMS) phys:CollidesWith(COLLISION.CHARACTERS) phys:CollidesWith(COLLISION.GIANTS) phys:SetCapsule(rad, height or 2) end For an obstacle (you'll find it in standardcomponents.lua). The third argument is what you want. Unfortunately it seems like this is a C function and you might not be able to access it so easily. You can get the Physics table from an entity with yourentity.Physics. You might want to print that table and see if one of the entry is what you want. Good luck. Edited July 13, 2017 by ZupaleX Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-938996 Share on other sites More sharing options...
alainmcd Posted July 13, 2017 Share Posted July 13, 2017 inst.Physics:GetHeight() Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-939008 Share on other sites More sharing options...
ZupaleX Posted July 13, 2017 Share Posted July 13, 2017 Much more efficient than my answer Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-939014 Share on other sites More sharing options...
. . . Posted July 14, 2017 Author Share Posted July 14, 2017 @alainmcd Sorry to bug you, but I'm trying to put my code to check if the entity's over 10 tall, but it crashes the game saying " :2544: calling 'GetHeight' on bad self (Physics expected, got table) " Do you maybe know what I'm doing wrong ? Here's the code! Spoiler for i, v in ipairs(colliders) do local height = GLOBAL.Physics:GetHeight() if v.height >= 10 then ToggleOnPhysics(inst) if inst.components.locomotor:WantsToMoveForward() then inst.sg:GoToState("hit") JumpCollideHit(inst) if v.components.workable then v.components.workable:WorkedBy(inst, .5) end if v.components.combat and v.components.health then v.components.combat:GetAttacked(inst, 20, nil) end end end end I also tried " v.Physics:GetHeight(>= 10) " but that didn't work either xD.. Also, if I want to check the height of something for example in beequeen.lua the height would be the value in the middle, correct? Like beequeen is 500 height? MakeFlyingGiantCharacterPhysics(inst, 500, 1.4) And thanks for your help man !! Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-939307 Share on other sites More sharing options...
ZupaleX Posted July 14, 2017 Share Posted July 14, 2017 (edited) you are calling GLOBAL.Physics:GetHeight() which is not what you want to do. You want to call GetHeigth on the object's Physics member. Where did you put the function you copy/pasted? Could you provide a bit more? EDIT: for your second question, I refer you to my answer containing the function MakeObstaclePhysics. I could give you a straight answer but I believe that if you are provided hints instead and look by yourself, it will be eventually more helpful. Edited July 14, 2017 by ZupaleX Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-939309 Share on other sites More sharing options...
. . . Posted July 14, 2017 Author Share Posted July 14, 2017 This is the entire local function JumpCollide in my modmain.lua, it's the code I use the make character collide with objects while jumping. It's very unefficient as you can see Spoiler AddPrefabPostInit("rock_ice", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("spiderhole", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("marblepillar", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("beequeenhivegrown", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("ancient_altar", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("ancient_altar_broken", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("pighouse", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("pigking", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("pigtorch", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("rabbithouse", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("mermhouse", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("beefalo", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("bishop", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("bishop_nightmare", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("minotaur", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("deerclops", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("koalefant_summer", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("koalefant_winter", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("walrus_camp", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("spiderqueen", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("tallbird", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("teenbird", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("tentacle_pillar", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("dragonfly", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("bearger", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("Goose", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("warg", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("antlion", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("spat", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("klaus", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("beequeen", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("toadstool", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("toadstool_dark", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("mushroomsprout", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("mushroomsprout_dark", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("stalker", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("stalker_forest", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("stalker_atrium", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("atrium_overgrowth", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("nightmarelight", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("cave_banana_tree", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("slurtlehole", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("insanityrock", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("sanityrock", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("stalagmite_full", function(inst) inst:AddTag("collider") end) AddPrefabPostInit("stalagmite_tall", function(inst) inst:AddTag("collider") end) local function JumpCollide(inst) local x, y, z = inst.Transform:GetWorldPosition() local walls = TheSim:FindEntities(x, y, z, 1, {"wall"}) local trees = TheSim:FindEntities(x, y, z, 1, { "tree" }) local boulders = TheSim:FindEntities(x, y, z, 1, { "boulder"}) local colliders = TheSim:FindEntities(x, y, z, 1) for i, v in ipairs(walls) do if v.components.health ~= nil and v.components.health:GetPercent() > .51 then ToggleOnPhysics(inst) if inst.components.locomotor:WantsToMoveForward() then inst.sg:GoToState("hit") JumpCollideHit(inst) end return end end for i, v in ipairs(trees) do if not v:HasTag("stump") then ToggleOnPhysics(inst) end if inst.components.locomotor:WantsToMoveForward() and not v:HasTag("stump") then inst.sg:GoToState("hit") JumpCollideHit(inst) if v.components.workable then v.components.workable:WorkedBy(inst, 1) end if v.components.combat and v.components.health then v.components.combat:GetAttacked(inst, 20, nil) end end return end for i, v in ipairs(colliders) do local height = GLOBAL.Physics:GetHeight() if v.height >= 10 then ToggleOnPhysics(inst) if inst.components.locomotor:WantsToMoveForward() then inst.sg:GoToState("hit") JumpCollideHit(inst) if v.components.workable then v.components.workable:WorkedBy(inst, .5) end if v.components.combat and v.components.health then v.components.combat:GetAttacked(inst, 20, nil) end end end end for i, v in ipairs(boulders) do ToggleOnPhysics(inst) if inst.components.locomotor:WantsToMoveForward() then inst.sg:GoToState("hit") JumpCollideHit(inst) end end end Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-939311 Share on other sites More sharing options...
ZupaleX Posted July 14, 2017 Share Posted July 14, 2017 I am not sure anymore what you are trying to achieve. 1) Why do you add the "collider" tag to all these entities? 2) Why do you call ToogleOnPhysics on inst? 3) What do you do with this function? You have the jump custom action working already? When is this JumpCollide called? Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-939313 Share on other sites More sharing options...
. . . Posted July 14, 2017 Author Share Posted July 14, 2017 I call ToggleOnPhysics cause when my character's supposed to collide with one of those objects he shouldn't be able to pass through them anymore since he's slamming into them. How my jump function works is there's a jump action which happens when you press a key, it then plays a unique state for jumping. While in the jumping state there's a perodictask of .1 playing JumpCollide function to check for any objects my character shouldn't be able to pass through (since all physics collision is turned off then you can pass through stuff), if it detects a "collider", "tree", "boulder", or "wall" he goes to JumpCollideHit function which completely cancels the jump since he's not supposed to be able to jump over those cause the jump anim doesn't go that high. That's why I want to know if there's a way I can just check for the height of entities then I don't have to put collider tag for every single prefab the jump shouldn't be able to go through . Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-939317 Share on other sites More sharing options...
ZupaleX Posted July 14, 2017 Share Posted July 14, 2017 Ok so when you trigger this action you toggle off the physics on your character right? I was asking about the "collider" tag because I do not see it used in your JumpCollide function. Your colliders variable is just all the entities which are close to inst currently. Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-939318 Share on other sites More sharing options...
. . . Posted July 14, 2017 Author Share Posted July 14, 2017 Yes, I toggle of physics on my character or else he wouldn't be able to pass through anything (to make it look like he's jumping) And here's how the collider part actually looks in JumpCollide function the original one I posted was just me trying to do the height check thing then I don't have to check for prefabs by tag anymore & just have 1 check for everything that's height surpasses my jump . Spoiler local colliders = TheSim:FindEntities(x, y, z, 1, { "collider"}) for i, v in ipairs(colliders) do ToggleOnPhysics(inst) if inst.components.locomotor:WantsToMoveForward() then inst.sg:GoToState("hit") JumpCollideHit(inst) if v.components.workable then v.components.workable:WorkedBy(inst, .5) end if v.components.combat and v.components.health then v.components.combat:GetAttacked(inst, 20, nil) end end end Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-939319 Share on other sites More sharing options...
ZupaleX Posted July 14, 2017 Share Posted July 14, 2017 OK so, the way I would approach this problem: Get rid of all the tag adding business and just retrieve all the entities around the players. Then make sure that the entity that you are currently checking has a member Physics! The immediate reason I can see for your crash is that you mentioned you tried doing for i, v in pairs(colliders) do ... v.Physics:GetHeight() ... end which is definitely better than the GLOBAL.Physics:GetHeight() for sure But what if v doesn't have a Physics member? (hint: it will crash) So I would investigate that Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-939321 Share on other sites More sharing options...
. . . Posted July 14, 2017 Author Share Posted July 14, 2017 (edited) Is this what you mean? Spoiler local colliders = TheSim:FindEntities(x, y, z, 1) for i, v in ipairs(colliders) do if v.Physics and v.Physics:GetHeight( >= 10) then ToggleOnPhysics(inst) if inst.components.locomotor:WantsToMoveForward() then inst.sg:GoToState("hit") JumpCollideHit(inst) if v.components.workable then v.components.workable:WorkedBy(inst, .5) end if v.components.combat and v.components.health then v.components.combat:GetAttacked(inst, 20, nil) end end end end Though, it crashed saying " :2544: unexpected symbol near '>=' " If it doesn't let me check if the entities greater than 10 height... does that mean I will have to put a elseif for every single height value I want to check for ?! Edited July 14, 2017 by SuperDavid Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-939323 Share on other sites More sharing options...
ZupaleX Posted July 15, 2017 Share Posted July 15, 2017 Looks better. Now let's check your call to GetHeigth GetHeigth doesn't take any argument. You are provideing an argument here by calling v.Physics:GetHeight( >= 10) and a very strange one on top of it! To be precise, GetHeight takes one argument which is the Physics object itself. But it is implicitly called when you do :GetHeigth() To be more explicit: v.Physics:GetHeight() would be the same as v.Physics.GetHeight(v.Physics) This function will return you the height of the entity. And that is this result that you need use in your comparison. v.Physics:GetHeight() >= 10 Hope it's clear enough. Let me know if my explanation is messy. Link to comment https://forums.kleientertainment.com/forums/topic/80556-solved-is-there-a-way-to-get-height-of-entity/#findComment-939327 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