Jump to content

AddForce weird behavior


Recommended Posts

I want to add force with offset to the center mass of body, lets say 1unit to X axis.

public class TEst : Component
{
	BodyRigid boat;
	public vec3 pos = new vec3(1,0,0);//force point

	void Init()
	{
		// write here code to be called on component initialization
		boat = node.ObjectBodyRigid;	
	}
	
	void UpdatePhysics()
	{
		if (Input.IsKeyPressed(Input.KEY.W))
		{
			boat.AddForce(pos, node.GetWorldDirection(MathLib.AXIS.Y)*40);
		}
	}
}

I suppose this shoud create rotation and translation. 

At the beginning when I press W key everything looks ok, but after some time body stops to rotate and his direction become ~90 degress. Rotational action not creates anymore, only translation works fine:

 

 

I found here is the some kind of similar problem, but I dont understand how to use it in my case.

I`ve used test example, assigned my script to cylinder and change only mass to 10 unit. Other params are default.

Can anyone explain the correct way or example how to use addforce with offset. 

Thanks
 

Spoiler

image.thumb.png.8fd668034edb7a9c4feec1c89f1ad256.png

image.thumb.png.1db14b3b4452bbdd30a637e58af024d9.png

 

Edited by sevas55
Link to comment

Hello! 

just use WorldForce instead of Force

//boat.AddForce(pos, node.GetWorldDirection(MathLib.AXIS.Y) * 50);
boat.AddWorldForce(node.ToWorld(pos), node.GetWorldDirection(MathLib.AXIS.Y) * 50);

For some reason, the regular addForce doesn't take into account the center of mass. I'm not sure if this is a bug or if there was some physical meaning - it needs to be checked. Thanks! 

  • Like 1
Link to comment
Posted (edited)

Thanks for response, Alexander!

Your code works correct for me.

I`ve seen another users also found this function not works as local force. 

If possible, check AddForce function.

 

Edited by sevas55
Link to comment
×
×
  • Create New...