Jump to content

Recommended Posts

Posted (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 by Skrakle
Posted

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.

Posted

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

Posted

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.

Posted

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.

Posted

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.

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.

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...