Realistic swinging physics

I’m looking for a way to take the very clunky movement in this scene and create something a little more realistic.
https://playcanvas.com/editor/scene/590768
I want the pearls to bump into the pointer and push it out of the way, until there is enough clearance for the pointer to swing back to its starting position. I’ve tried using rigidbodies with small blocks to limit the pointers movement, but it doesn’t swing back into place, as shown in this scene: PlayCanvas | HTML5 Game Engine
Any suggestions?

If you are still going the physics route, I would use a ‘joint’ and attach it to the pivot of the arrow. Physics joints haven’t been exposed via the PlayCanvas API but can be used in the ammo.js system.

Look at ‘constraints.js’ and refer to the Bullet phyiscs API, Wiki and forums for more information.

I did something similar in Virtual Voodoo to attach the doll to the hook: https://www.miniclip.com/games/virtual-voodoo/en/

Alright that looks like something that would work. Another thing I’m trying to fix related to this is how to stop the rigidbodies I use for the pearls from moving out of place after contacting the pointer. Would a joint potentially fix this as well or is there some other secret physics component that would work? Also, do you have a link to anything about the ammo.js? I found a post titles intro to ammo.js but there’s nothing there.
https://blog.playcanvas.com/introduction-to-ammo-js/

You are probably best off using compound physics rigid bodies (effectively gluing two or more rigid bodies together) and using a joint/restricted rigid body on the wheel’s pivot point.

In a nutshell: Big wheel rigid body that can only spin, compound the pearls to the wheel.

I’m only trying to use the rigidbody to make the pointer move when the pearls contact it, I’ve got the wheel moving without physics. It’s a bit of a confusing process, because the idea is to randomly select which prize on the wheel the player wins, then make it seem as though the wheel randomly stopped on that spot. The pointer movement is the tricky part, I have a system set up to move it on a trigger, but the movement isn’t very convincing and the best way I can think of to fix this would be to joint the pivot, as @yaustar suggested, and let the physics move the pointer around when the pearls contact it.

You are going to have to do all using physics or all not at all otherwise you are going to have one hell of a time syncing the wheel with the pearls.

Are the pearls kinematic? If not, try that. In theory, they shouldn’t react to collisions.

I was thinking that actually. But what I’m finding is my biggest problem with the rigidbodies is that mesh collisions don’t work unless they are static. The easiest way I could think of making this work would be to somehow make the pearls a child of the wheel, give them a static rigidbody, and somehow make them move as the wheel changes its rotation. I’m not sure the pearls rigidbodies would actually move though.

Could you not make the pearls spheres?

I was thinking that to, I’m just not sure how I’d get them to rotate around the axis of the wheel.
I made a post on this to.

This is how I would do it if I had to use physics.

I’ve tried this, but the rigidbodies didn’t move with the “wheel”. The scene in the second link from my initial post shows all of the ways I’ve attempted to create interactions between the pearls and the pointer. The one on the right in the middle uses sphere rigidbodies as children of the pearl ring. However, the child rigidbodies don’t interact with the pointer, and without being able to display the actual rigidbody when I launch the game I can’t be sure if they’re actually moving or if it’s just the model that’s moving.

As far as I can tell, you haven’t compounded the rigid bodies together in the scene you linked to. (See notes on it here in Bullet: http://bulletphysics.com/Bullet/BulletFull/classbtCompoundShape.html)

I’ve managed to get the pearls ‘spinning’ but did have a number of bugs which compounding should help with.

When using kinematics, you have to set the velocity directly. They don’t react to forces. https://playcanvas.com/editor/scene/591432

I still think physics is the wrong way to go about this and you should drop trying to use it for this. (Like the Aladdin video I linked to in a different post).

I understand what you did in this. I’ve noticed that one or two of the capsules in this go out of sync when it gets close to stopping though.
I got it working with the wheel model and spheres here.
https://playcanvas.com/editor/scene/590768

Would the equation you use to slow the angular velocity work in a similar way if I were just setting the rotation of the entity every frame?

On second thought, I think i just found the answer.

var RotateRing = pc.createScript('rotateRing');

//var colliders;
var wheel;

// initialize code called once per entity
RotateRing.prototype.initialize = function() 
{
    //colliders = this.app.root.findByTag('Collider');
    wheel = this.app.root.findByName('Wheel2');
};

RotateRing.prototype.spin = function()
{
    /*
    for(i=0;i<colliders.length;i++)
    {
        colliders[i].rigidbody.angularVelocity = new pc.Vec3(0,100,0);
    }
    */
    wheel.rigidbody.angularVelocity = new pc.Vec3(0,1000,0);
};

RotateRing.prototype.update = function(dt)
{
    /*
    for(i=0;i<colliders.length;i++)
    {
        var v = colliders[i].rigidbody.angularVelocity;
        v.y *= 0.995;
        colliders[i].rigidbody.angularVelocity = v;
    }
    */
    var v2 = wheel.rigidbody.angularVelocity;
    v2.y *= 0.995;
    wheel.rigidbody.angularVelocity = v2;
};

Ignoring everything that’s commented out of course.