How to use Weldjoints

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
kloki
Prole
Posts: 4
Joined: Thu Jul 26, 2012 10:13 am
Location: Netherlands

How to use Weldjoints

Post by kloki »

Im trying glue object together using the weld joints. My goal is to add specific sensors to a main collision box. This way I can use collision callback to register head collision, foot collisions etc. The problem is I cant seem to get the weldjoints to work. I tried the wiki but the documentation is kind of sparse.

Below is the code how I initialize everything. At the moment the two objects act as if they are not connected. What am I doing wrong? I think I got the anchors right.

Code: Select all

   
   self.body = love.physics.newBody(gameworld,self.x,self.y,"dynamic")
   self.shape = love.physics.newRectangleShape(32,64)
   self.fixture = love.physics.newFixture(self.body,self.shape,1)
   self.fixture:setUserData("player")
   self.body:setFixedRotation( true )  
   self.fixture:setRestitution(0.1)
   
   --foot sensor
   self.footsensor={}
   self.footsensor.body = love.physics.newBody(gameworld,self.x,self.y+33,"dynamic")
   self.footsensor.shape = love.physics.newRectangleShape(20,2)
   self.footsensor.fixture = love.physics.newFixture(self.footsensor.body,self.footsensor.shape,1)
   self.footsensor.fixture:setUserData("playerfoot")
   self.footsensor.body:setFixedRotation( true )
   self.footsensor.fixture:setSensor(true)

   --weldjoint
   self.footjoint=love.physics.newWeldJoint(self.body,self.footsensor.body,16,63,10,1,false)
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: How to use Weldjoints

Post by Boolsheet »

I'm not sure, but I think Box2D just skips the sensor fixture when it tries to apply constraints and that makes it a body without fixtures and shapes. Can't you just add the sensor fixture to the main body instead of giving it its own? Bodies can have multiple fixtures attached to them. You also don't have to involve the soft WeldJoint that way.
Shallow indentations.
User avatar
juno
Citizen
Posts: 85
Joined: Thu May 10, 2012 4:32 pm
Location: London

Re: How to use Weldjoints

Post by juno »

Boolsheet is right.
You don't need to use weld joints in your case. Try something like:

Code: Select all

self.body = love.physics.newBody(gameworld,self.x,self.y,"dynamic")
   self.shape = love.physics.newRectangleShape(32,64)
   self.fixture = love.physics.newFixture(self.body,self.shape,1)
   self.fixture:setUserData("player")
   self.body:setFixedRotation( true )  
   self.fixture:setRestitution(0.1)
   
   self.footShape = love.physics.newRectangleShape( 0, 33, 20,2, 0 )
   self.footFixture = love.physics.newFixture(self.body,self.footShape,1)
   self.footFixture:setUserData("playerfoot")
The collision callbacks will be triggered with whatever body part is colliding.
wat ya mean she's in another castle!?
kloki
Prole
Posts: 4
Joined: Thu Jul 26, 2012 10:13 am
Location: Netherlands

Re: How to use Weldjoints

Post by kloki »

I didn't know you could do that. This is good to know :) Works Perfect
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 56 guests