Jump to content

Collision Reset?


GSFC_1
 Share

Recommended Posts

hey guys, 

got a high fast one thrown at me today, it involves collisions, which i have not been able to fully immerse myself into. 

We are learning to use leadwerks over here and we have set up a collision test. It involves a rotating box, with a "laser pointer" shooting a ray out of it. there are 3 other boxes on the floor, each sitting pretty, doing nothing. When the laser pointer spins, the laser eventually contacts the surface of the box. This causes the API to change the color of the collided-with box, to red. This is what we wanted. The second the laser touches the box, it changes color to red, but after the laser pointer is no longer in contact with the box, the box stays red. We want the box to change back to iits original color. Its as if the collision system needs to be reset? Is that the case? 

Standby, my co-worker will send me the code he has been working on .  

Link to comment
Share on other sites

You could make an EnterExit trigger. Not sure if you are using Lua, but you could be doing something similar in C++.

Script.enabled = true
Script.entered = false
Script.exited = false
Script.collided = false

function Script:UpdatePhysics()
	if self.enabled then
		if self.entered then
			if self.collided == false then
				System:Print("Exiting the trigger")
				self.exited = true
				self.entered = false
			end
		end	
			
		self.collided = false
	end	
end

function Script:Collision(entity, position, normal, speed)
	if self.enabled then
		self.collided = true
		
		if self.entered == false then
			System:Print("Entered the trigger")
			self.entered = true
			self.exited = false
		end
	end	
end

 

  • Upvote 1
Link to comment
Share on other sites

I think I complcated the issue by trying to change colors.

The problem simplified  is this:
I have a long slender box that I rotate with this line of code 

 self.entity:Turn(0,.5,0)

Then I check for collisions with other objects.

function Script:Collision(entity, position, normal, speed)    
    myname = entity:GetKeyValue("name")    
    System:Print(myname)
end

This prints the name of each object that collides with the long box.
Works perfectly. 
Once. 
As the box rotates around and collides with the objects a second time nothing happens.

I tried AggorJorn's code and it does the same as mine. It prints "Entered the trigger" and "Exiting the trigger" for each object once. Subsequent collisions are ignored.

It appears after an object has recorded a collision something needs to be reset before the next collision.

  • Upvote 1
Link to comment
Share on other sites

When you use commands like Turn, Move, SetPosition, etc. you are overriding the physics simulation. The correct way to do this is to use a kinematic joint, which allows you to set a target position or rotation, and it uses physics forces to acquire that orientation.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I'm going to add a new overload to Entity:GetDistance() like this:

float Entity::GetDistance(Entity* entity, const bool useshape)

If useshape is true it will find the closest point between the two entities using their collision shape. When this is equal to zero, the entities are intersecting.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • 2 weeks later...

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