Jump to content

To select collision just for some objects


aldoz
 Share

Recommended Posts

Hi again guys,

 

I am trying to get this situation :

 

You use a player on a terrain; in front of player there is a wall.

Near the player there are some little stones ready to be throw to the wall!.

 

Ok what I would is to obtain the player CAN'T go through the wall but the stones yes!

 

Obviously if I turn off collision for the stones so I will get my stones sink inside the terrain. So I need something to choose for each of the objects , which are the other objects with which to have a collision..

In other words :

Stone 1 ------> Can collide with Stone2 and Stone3 - Can't collide with Wall

Stone 2 ------> Can collide with Stone 1 - Can't collide with Stone3 and Wall

 

Can I obtain something like that?

Link to comment
Share on other sites

  • 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

I am using this rule :

 

Wall = prop

Stone = trigger

 

and they continuing to collide!

So I tried this too :

 

Wall = character

Stone = debris

 

But again.. the collision between the wall and the stones continuing to be active!

 

So what is wrong??

Link to comment
Share on other sites

The terrain should be scene. You want the player to collide with the wall. And you want the stones to collide with the scene and with each other but not the wall. So you can either make the stones a custom collision type/response or you can make the wall a custom collision type/response.

example:

window = Window:Create("example",0,0,800,600,257)

context = Context:Create(window)

world = World:Create()

light = DirectionalLight:Create()

light:SetRotation(35,45,0)

camera = Camera:Create()

camera:SetMultisampleMode(2)

camera:SetPosition(0,4,-4)

 

ground = Model:Box()

ground:SetScale(10,1,10)

ground:SetColor(0.1,1,0.3)

shape = Shape:Box(0,0,0, 0,0,0, 10,1,10)

ground:SetShape(shape)

ground:SetCollisionType(Collision.Scene)

 

wall = Model:Box()

wall:SetPosition(-2,3,0)

wall:SetScale(2,.1,2)

wall:SetColor(1,1,0)

shape = Shape:Box(0,0,0, 0,0,0, 2,.1,2)

wall:SetShape(shape)

wall:SetCollisionType(Collision.Prop)

 

Collision.Custom = 10

Collision:SetResponse(Collision.Custom,Collision.Custom,Collision.Collide)

Collision:SetResponse(Collision.Custom,Collision.Scene,Collision.Collide)

 

wall = Model:Box()

wall:SetPosition(2,3,0)

wall:SetScale(2,.1,2)

wall:SetColor(1,1,0)

shape = Shape:Box(0,0,0, 0,0,0, 2,.1,2)

wall:SetShape(shape)

wall:SetCollisionType(Collision.Custom)

 

ball1 = Model:Sphere(16)

ball1:SetColor(1,0,0)

shape = Shape:Sphere(0,0,0, 0,0,0, 1,1,1)

ball1:SetShape(shape)

ball1:SetMass(1)

ball1:SetPosition(-2,10,0)

ball1:SetCollisionType(Collision.Custom)

 

ball2 = Model:Sphere(16)

ball2:SetColor(1,0,1)

shape = Shape:Sphere(0,0,0, 0,0,0, 1,1,1)

ball2:SetShape(shape)

ball2:SetMass(1)

ball2:SetPosition(2,10,0)

ball2:SetCollisionType(Collision.Custom)

 

while not window:KeyHit(Key.Escape) do

if window:Closed() then return false end

Time:Update()

world:Update()

world:Render()

context:Sync(true)

end

  • 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

Damn I can't get working your code...

 

I am inside in a custom "terrain example" project.

Take the terrain example, add a wall in front of player and a little box (as stone) on the groud and you know my situation.

 

I try to put your code in a blank project using the script editor but I get just a black screen..

anyway I suppose that I could to use some pieces of your code directly as script for the wall and the stones...

 

Collisions start to be hard to handle for me :\

 

 

EDIT : ok I run your example adding your code in the player script.. (lol)..

So I get 2 windows, one is the game and one is your example.. and yes I see you got the point!

 

Now I hope to find some way to add to my code..

Link to comment
Share on other sites

Ok I am trying to set your collision code for single objects; so I selected a single stone object and I put this code in his script page:

 

Collision.Custom = 10
Collision:SetResponse(Collision.Custom,Collision.Custom,Collision.Collide)
Collision:SetResponse(Collision.Custom,Collision.Scene,Collision.Collide)
self.entity:SetCollisionType(Collision.Custom)

 

But I get : Script Error attempt to index global 'self' (a nil value)..

I think I not yet catch the right logic behind Leadwerks..

Link to comment
Share on other sites

Ok, I tried many things and finally I solve this trouble.

 

Just the terrain example born with some strange collision behaviour or maybe just me editing and changing too much the terrain example..

 

So I restart my project using the ball game example and I notice that the collision behaviour follow the previous mentioned collision rules :

http://www.leadwerks.com/werkspace/page/api-reference/_/command-reference/collision-r778

 

So now If use the stones as debris and the wall as character I get my stones pass through wall but the player not.

So solved smile.png

Thank you guys

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