Box2d body can be set with linear damping, while Nape body seems to have no method for setting linear damping. That's strange!

Box2d body can be set with linear damping, while Nape body seems to have no method for setting linear damping. That’s strange!

The method of setting linear damping for the body in box2d seems to be non-existent in nape!

body.setLinearDamping(1);

The method of turning off and turning on gravity effects in box2d does not work!

body.setGravityScale(0);

On the contrary, it is this attribute that plays a role

body.m_gravityScale = 0;

As an explorer, I simply provide feedback to the community on the issues I have discovered

This method doesn’t work, does it need to be fixed?

01

02

Directly setting attributes to take effect

03

04

I’m not familiar with Box2D, but at a glance, it does appear the getter and setter are working with a different variable.

	/**
	 * Get the gravity scale of the body.
	 */
	public function getGravityScale():Float
	{
		return m_gravityScale;
	}

	/**
	 * Set the gravity scale of the body.
	 */
	public function setGravityScale(scale:Float):Void
	{
		m_angularDamping = scale;
	}

box2d.dynamics.B2Body.hx

@joshtynjala

Are you sure you didn’t write the wrong attribute during the migration?

I also noticed that the method of setting gravity uses angle damping instead of gravity properties.

Careful @785597448 :face_with_raised_eyebrow:

Can I suggest you try putting a copy of B2Body.hx in your own project, and modifying lines 896-907 to this:

	/**
	 * Get the gravity scale of the body.
	 */
	public function getGravityScale():Float
	{
		return m_gravityScale;
	}

	/**
	 * Set the gravity scale of the body.
	 */
	public function setGravityScale(scale:Float):Void
	{
		m_gravityScale = scale;
	}

Really, the only thing changing there is changing m_angularDamping to m_gravityScale.

I make no promises here, I’ve not tried it, and again I’ll stress, I’m not familiar with Box2D. Attempt this at your own risk.

I have already @ jostynjala, and I dare not try it randomly. I am worried that it will affect other functions, so I can only wait for @ jostynjala’s response

There is a setAngularDamping() method directly above the getGravityScale() method. It uses the m_angularDamping variable.

public function setAngularDamping(angularDamping:Float):Void
{
	m_angularDamping = angularDamping;
}

This does indeed seem like a simple oversight by the person who ported this class to Haxe. Changing setGravityScale() to set the m_gravityScale variable should be the correct solution.

public function setGravityScale(scale:Float):Void
{
	m_gravityScale = scale;
}

I have pushed this change to the Git repo.

1 Like

Okay, thank you for your response