Jump to content

CollisionTrigger.lua


DanceTweety
 Share

Recommended Posts

I am trying to make a trigger box to detect a ball using CollisionTrigger.lua.

But it only detects the player.

 

How can I change this the ball is a prop and has a phy file.

 

Any help is welcome smile.png

 

 

I also tried the Selective Collision Trigger 1.0 but it does also not detect the ball

 

I also dont see how I can put a Entity in the box and even it I place it in the script it does not show up in the input box.

Link to comment
Share on other sites

You have to identify the ball somehow. You can just use it's name if you like. Inside the collision box script you can check the passed in entity "name" key value to see if it's the ball.

 

if entity:GetKeyValue("name") == "Ball" then

end

 

Assuming the balls name in the editor is called "Ball"

Link to comment
Share on other sites

This is how it is looking now:

 

 

--[[This script will make any entity act as a collision trigger.  It works best when you set the
entity's collision type to "Trigger".  This will continuously detect collisions without causing
any physical reaction.
]]--

function Script:Start()
   self.enabled=true
end

function Script:Collision(entity, position, normal, speed)
   if self.enabled and entity:GetKeyValue("Name") == "ball"
 	  then
 	  self.component:CallOutputs("Collision")
   end
end

function Script:Enable()--in
   if self.enabled==false then
    self.enabled=true
       self:CallOutputs("Enable")
   end
end

function Script:Disable()--in
   if self.enabled then
    self.enabled=false
    self:CallOutputs("Disable")
   end
end

 

 

It does not react on Player what is good but also does not react on ball (this is what the entity is called in the scene).

It seem it will not react on a prop.

Same happens in the Selective Collision Trigger 1.0 script.

Link to comment
Share on other sites

This is how the script in the ball looks it is linked in flowchart editor to out of CollisionTrigger.lua script.

 

Script.score = "0"
Script.hit_test1 = false
Script.hit_test2 = false

function Script:Ball_hit1()--in
self.hit_test1 = true
 if self.hit_test1 == true then
 self.score = "50"
 end
end

--[[function Script:Ball_hit2()--in
 self.hit_test2 = true
 end
]]--

function Script:PostRender(context)
context:SetBlendMode(Blend.Alpha)
	 if self.hit_test1 == true or self.hit_test2 == true then
local context=Context:GetCurrent()
 context:SetBlendMode(Blend.Alpha) --Set blend to alpha so only letters will show
		 context:DrawText("Score: ".. self.score .."",5,150) --Set text and position of text
 else
local context=Context:GetCurrent()
		 context:SetBlendMode(Blend.Alpha) --Set blend to alpha so only letters will show
		 context:DrawText("Score: ".. self.score .."",5,150) --Set text and position of text
 end
end

 

If I put in Player in the CollisionTrigger.lua script instead of ball it works fine.

Also try Name instead of name in CollisionTrigger.lua script but then script did not work any more when I tested it with Player.

Link to comment
Share on other sites

Some control would be nice. smile.png

 

edit--

 

I just remembered seeing this post a while back that was talking about how you can change collision response types. I've never gotten it to work though.

 

http://www.leadwerks.com/werkspace/topic/9109-collision-response-types/page__hl__collision%20type#entry69329

 

Yes, it's just a little convoluted:

PhysicsDriver::GetCurrent()->virtual void SetCollisionResponse(const int collisiontype0, const int collisiontype1, const int response);

 

That should really be simplified.

Link to comment
Share on other sites

Yeah it will generate the Character Controller cylinder physics which is unwanted in many cases including this one most likely.

 

A work around is to move your entity and then make an invisible entity with character physics that will follow it (using SetPosition() and SetRotation()). Give your entity Debris collisiontype to avoid collisions with the invisible entity(with Character Controller physics) following it.

Might not be perfect but that is what I am doing until I can make custom collision responses and it works pretty good.

  • Upvote 1
Link to comment
Share on other sites

No did not change Physics Mode from Rigid Body to Character need it to be ball shaped.

 

Yeah it will generate the Character Controller cylinder physics which is unwanted in many cases including this one most likely.

 

A work around is to move your entity and then make an invisible entity with character physics that will follow it (using SetPosition() and SetRotation()). Give your entity Debris collisiontype to avoid collisions with the invisible entity(with Character Controller physics) following it.

Might not be perfect but that is what I am doing until I can make custom collision responses and it works pretty good.

 

This maybe a option I wonder what will happen when I shoot it in a hole though.

Link to comment
Share on other sites

Yeah it will generate the Character Controller cylinder physics which is unwanted in many cases including this one most likely.

 

A work around is to move your entity and then make an invisible entity with character physics that will follow it (using SetPosition() and SetRotation()). Give your entity Debris collisiontype to avoid collisions with the invisible entity(with Character Controller physics) following it.

Might not be perfect but that is what I am doing until I can make custom collision responses and it works pretty good.

 

I have try that now Trigger will work it change its Physics Mode from Rigid Body to Character Controller.

But then it does not roll off course.

When you make object and make that a child of the ball all kinds of strange things happen. I get a giant ball in the scene and it will not detect any way.

 

So seams is no way to get a ball to be detected.

Link to comment
Share on other sites

Your code works fine by just setting the ball's collisiontype to "character". No need to change the actual physics shape..

 

If Josh would fix the apparent bug with the 'Collision:SetResponse' command, then you could just set the type/response that you want via code.

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

The program I am making is using the physics engine so making a program to follow the ball using SetPosition() and SetRotation() would be us less.

 

Why cant I like Macklebee is saying set the Collision respons becouse it seems to do notthing at the moment.

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...