Jump to content
  • 0
GSFC_1

Collision Reset?

Question

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 .  

Share this post


Link to post

9 answers to this question

Recommended Posts

  • 1

i hope i understand your problem correctly.
But as i see it, you would have to manually set the color back to its original color.

Share this post


Link to post
  • 0

ya, I think I am starting to realize this. The color change needs to be configured to be momentary. 

 

Share this post


Link to post
  • 0

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

 

Share this post


Link to post
  • 0

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.

Share this post


Link to post
  • 0

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.

Share this post


Link to post
  • 0

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

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

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