 # How to move dynamic actor to look like it vibrate? PhysX 3.2.x

Hi! My problem is How to move dynamic actor to look like it vibrate (oscillate)? (for example in one axis)
My idea is to move it sinusoidal by setVelocity but "for loop" executes in a few ms and my actor move only in one direction.
How to vibrate (move) object with constant frequency? What about mass and inertia?

Here’s my code.

``````vector<PxReal> k;
PxVec3 vel(0.0f, 0.0f , 0.0f);

for(int i = 0; i < 360; i ++)
{
k.push_back( sin( double( 2*3.14* i ) ));
PxVec3 vel(2*k[i],0.0 , 0.0f);

actors.at(0)->isRigidDynamic()->setLinearVelocity(vel,true);

}
``````

I think maybe you can randomly generate a velocity

Are you using a kinematic, or a non-kinematic dynamic?
Thanks,
Mike

Or you can call setGlobalPose directly.

I’ve already found the solution. I convert non-kinematic actor to kinematic and use
myActor->isRigidDynamic()->setKinematicTarget( target );

I have a question about time of simulation. I can move my object but I want to get the frequency of oscillation. I’ve already got the FPS (~60fps) of rendering but is it my frequency? I use GLUT library for rendering and it looks more or less like this:
//…
//initialize glut functions
glutDisplayFunc(onRenderCallback);
glutMainLoop();
///
.
.
///
onRednerCallback()
{
StepPhysX();
}

``````StepPhysX(void)
{
gScene->simulate(myTimestep / 0.5);   // PxReal myTimestep = 1.0 / 60.0

//...perform useful work here using previous frame's state data

while(!gScene->fetchResults() )
{
// do something useful

PxTransform trans( PxVec3(amplitudeX*k[s], amplitudeY*k[s] + 10.0f, amplitudeZ*k[s]));
myActor->isRigidDynamic()->setKinematicTarget( trans );
// k - 180 elements vector of sine wave samples
}
}
``````