B2d get linear velocity from local point error

Hello,

Im fairly new to DEFOLD. I am running into an error with the following code

function init(self)
	local url = msg.url(nil, "go", "collisionobject")
	local body = b2d.get_body(url)

	b2d.body.get_linear_velocity_from_local_point(body,  vmath.vector3(1, 1, 1))
	
end

and its returning the following error:

ERROR:SCRIPT: main/main.script:8: bad argument #1 to 'get_linear_velocity_from_local_point' (vector3 expected, got userdata)
stack traceback:
  [C]:-1: in function get_linear_velocity_from_local_point
  main/main.script:8: in function <main/main.script:1>

Thanks for the help

Oh, looks like a bug in Defold:

static int Body_GetLinearVelocityFromLocalPoint(lua_State* L)
{
    b2BodyId* body = CheckBody(L, 1);
    b2Vec2 p = CheckVec2(L, 1, GetPhysicsScale());

It’s expecting the first argument to be a physics body, but also a vector.

Thank you for the reply and help. It also occurs with get_linear_velocity_from_world_point. Should I post an issue on github. Whats the best way to document this error?

I created a bug report the defold github

Defold Bug Report

1 Like

So in the mean time while this bug get fixed I think this bit of code should give you the same/similar results.

function get_world_point_velocity(point, body)
	local angularVelocity = go.get(body, "angular_velocity")
	local linearVelocity = go.get(body, "linear_velocity")
	return linearVelocity + vmath.cross(angularVelocity, point - go.get_position(body))
end