I've been working with using the above velocity tricks, but I'm getting unpredictable behaviour when running conveyors on slow speeds.
Link to sample scene:
https://www.dropbox.com/s/0posq8dzc0t4w ... m.ttt?dl=0
The code is (hopefully) self-explanatory:
Code: Select all
if (sim_call_type==sim_childscriptcall_initialization) then
-- fill a table with conveyor shape handles
tblHnd={}
for i=1,4,1 do
tblHnd[i]=simGetObjectHandle("conv"..i)
end
-- Get Y size of (any) conveyor shape bouding box
local r,mmin=simGetObjectFloatParameter(tblHnd[1],sim_objfloatparam_objbbox_min_y)
local r,mmax=simGetObjectFloatParameter(tblHnd[1],sim_objfloatparam_objbbox_max_y)
local sy=mmax-mmin
-- Calculate distance of boundig box center to circle center
local numRadius=1.5 -- radius of the conveyor
numDistance=(sy/2)-numRadius
numAngularVel=2*math.pi/30 -- angular velocity set so that we travel the full circle in 30 seconds
end
if (sim_call_type==sim_childscriptcall_actuation) then
for i=1,4,1 do
simResetDynamicObject(tblHnd[i])
-- Set angular velocity
simSetObjectFloatParameter(tblHnd[i],sim_shapefloatparam_init_velocity_g,numAngularVel)
-- Move angular velocity axis by applying linear velocity, based on the speed and distance calculated before
local m=simGetObjectMatrix(tblHnd[i],-1)
m[4]=0
m[8]=0
m[12]=0
local tblAbsLinearVelocity=simMultiplyVector(m,{numDistance*numAngularVel,0,0})
simSetObjectFloatParameter(tblHnd[i],sim_shapefloatparam_init_velocity_x,tblAbsLinearVelocity[1])
simSetObjectFloatParameter(tblHnd[i],sim_shapefloatparam_init_velocity_y,tblAbsLinearVelocity[2])
simSetObjectFloatParameter(tblHnd[i],sim_shapefloatparam_init_velocity_z,tblAbsLinearVelocity[3])
end
end
if (sim_call_type==sim_childscriptcall_sensing) then
end
if (sim_call_type==sim_childscriptcall_cleanup) then
end
When running this at the above settings (travel the complete circle in 30 seconds), it looks OK. Not perfect, but fit for purpose. However, when I change it to travel in 60 seconds, behaviour is getting strange.
Been banging my head against a wall on this problem for a while now... Can anybody tell me what I'm doing wrong here?
Thanks!