Strange movements box2d[SOLVED]

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
User avatar
AdrianN
Citizen
Posts: 73
Joined: Wed Mar 28, 2018 5:13 pm
Location: Lima

Strange movements box2d[SOLVED]

Post by AdrianN »

Hi, I'm making a top down game with box2d, at the moment I have a problem with a strange movement, with two bodies collides between theirs. This event appear only with I create a extra fixture (fixture_melee).

Fixture_melee is a sensor to simulate a melee attack.

To move the body I use only setLinearVelocity , velocity,x and velocity.y is print in the screen.


Image

Code: Select all

--modelo.lua (model class)
self.collider=py.newBody(self.entidades.world,x,y,"dynamic")
self.collider:setMass(10)
self.shape=py.newCircleShape(r)
self.fixture=py.newFixture(self.collider,self.shape)
self.fixture:setGroupIndex( -self.creador )
self.fixture:setUserData( {data="personaje",obj=self} )

self.collider:setInertia( 0 )
self.collider:setGravityScale( 0 )

self.ox,self.oy=self.collider:getX(),self.collider:getY()

self.rad=self.shape:getRadius()
self.shape_escudo=py.newCircleShape(r*2.5)
self.fixture_escudo=py.newFixture(self.collider,self.shape_escudo)
self.fixture_escudo:setSensor( true )
self.fixture_escudo:setGroupIndex( -self.creador )
self.fixture_escudo:setUserData( {data="escudo",obj=self}  )
	
--Radian.lua
--inicializate model class
Modelo.init(self,x,y,20)

self.shape_melee=py.newRectangleShape(50,0,100,75)
self.fixture_melee=py.newFixture(self.collider,self.shape_melee)
self.fixture_melee:setSensor( true )

self.fixture_melee:setGroupIndex( -self.creador )
self.fixture_melee:setUserData( {data="melee",obj=self}  )	
	
Attachments
game.love
(68.14 KiB) Downloaded 63 times
Last edited by AdrianN on Wed Mar 20, 2019 3:00 pm, edited 1 time in total.
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Strange movements box2d

Post by pgimeno »

I can't tell for sure, but it seems to me that you need fixed rotation. Try self.collider:setFixedRotation(true).

Alternatively, you can set the density of the melee fixture to 0 and call resetMassData on the body.

My opinion is that the eccentricity of the melee sensor causes collisions to introduce angular momentum, due to the displacement of the centre of mass. Then setAngle interferes with the momentum calculation, causing the momentum velocity to be applied in the wrong direction.
User avatar
AdrianN
Citizen
Posts: 73
Joined: Wed Mar 28, 2018 5:13 pm
Location: Lima

Re: Strange movements box2d

Post by AdrianN »

pgimeno wrote: Wed Mar 20, 2019 6:49 am I can't tell for sure, but it seems to me that you need fixed rotation. Try self.collider:setFixedRotation(true).

Alternatively, you can set the density of the melee fixture to 0 and call resetMassData on the body.

My opinion is that the eccentricity of the melee sensor causes collisions to introduce angular momentum, due to the displacement of the centre of mass. Then setAngle interferes with the momentum calculation, causing the momentum velocity to be applied in the wrong direction.
Thanks pgimeno, self.collider:setFixedRotation(true) work fine.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 73 guests