Skrakle Posted March 5, 2015 Share Posted March 5, 2015 (edited) I have a collision script attached to several models and i'm trying to detect whether their on the ground or in the air. Problem is, when a collision scene is detected, i don't know which entity touched down. function Script:Collision(entity, position, normal, speed) if (entity:GetClass()==20) then -- terrain -- can jump end end Edit: I was able to figure out a way using a Script.entityIndex variable in the collision script for each entity. Edited March 5, 2015 by Skrakle Quote Link to comment Share on other sites More sharing options...
BluHornet Posted March 6, 2015 Share Posted March 6, 2015 you can access the key values of the colliding entity with GetKeyValue and then check if the name is the same name as your floor / ground. The colliding entity and collision position is passed into the method by parameter. Quote Link to comment Share on other sites More sharing options...
Skrakle Posted March 6, 2015 Author Share Posted March 6, 2015 The problem was detecting which character touched the ground and in the Script:Collision function, there's only one entity parameter and i needed to identify the model that touched the terrain entity. Since i'm using an array for my characters, i only needed to set an index value on top of the script and it is set when a model is loaded. Script.entityIndex=-1; Script.entityJumping=0; function Script:Start() end function Script:Collision(entity, position, normal, speed) if (entity:GetClass()==20) then self.entityJumping=0; end if (entity.type == "char") then --self.component:CallOutputs("Collision") end end Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 6, 2015 Share Posted March 6, 2015 But every character has this script attached right? So every item that has a collision with the ground will each call its own Collision Function. Quote Link to comment Share on other sites More sharing options...
Skrakle Posted March 6, 2015 Author Share Posted March 6, 2015 Yes, i attached the collision script on all of them using SetScript like you previously suggested Quote Link to comment Share on other sites More sharing options...
BluHornet Posted March 6, 2015 Share Posted March 6, 2015 so could you try this? Add to the ground script that a collision calls a function in the script of the colliding object. That function could iterate through the array and call to the parts that need told that the character is on the ground. Another way is to use GetVelocity (http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/entity/entitygetvelocity-r73) to check if the y velocity is above a set Dead zone. The dead zone is to detect walking up and down stairs from being airborne. A third way is to check the distance from whatever member of the array to the ground and if it is greater than the normal +/- a dead zone value then you are not on the ground. Quote Link to comment Share on other sites More sharing options...
Skrakle Posted March 6, 2015 Author Share Posted March 6, 2015 Detecting if a character is on the ground or in the air is easy by using entity:GetAirborne() Quote Link to comment Share on other sites More sharing options...
BluHornet Posted March 6, 2015 Share Posted March 6, 2015 Oh I missed the issue sorry. Have you resolved this problem yet? If not what entity needs to know which entity collided with the ground? If it is the ground itself then that is easy. That data is the entity parameter of the collide function. I would just set a self.lastCollidedEntity and then in the collide function have a line like .. self.lastCollidedEntity = entity If another entity needs to know I would do the above to the ground and then in the function that needs to know you can retrieve that variable from the ground. Quote Link to comment Share on other sites More sharing options...
BluHornet Posted March 6, 2015 Share Posted March 6, 2015 Actually I though of a another idea. In the collide function of the ground script add if entity.script.groundCollision ~= nil then entity.script.groundCollision = true end Add a variable to the objects in the array groundCollision = false. Then when you use that variable for what ever you are doing reset the groundCollision to false. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.