Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ho to move a kinematic rigid body with mouse with Vector3 #392

Open
oliverellmers opened this issue Feb 16, 2022 · 2 comments
Open

Ho to move a kinematic rigid body with mouse with Vector3 #392

oliverellmers opened this issue Feb 16, 2022 · 2 comments

Comments

@oliverellmers
Copy link

Hello,

I am working in THREE.JS with the ammo.js port, and can not figure out ow to go above apply simply XYZ postiion transformaitons to a rigidbody that i woul dliek to use to hit other soft bodies.

Is there are example or documentaiton on how to do with with X Y Z mouse input?

@oliverellmers oliverellmers changed the title Ho to move a kinematic rigid body with mouse xyx vector Ho to move a kinematic rigid body with mouse with Vector3 Feb 16, 2022
@willeastcott
Copy link
Contributor

Are you asking how to set up kinematic bodies? (If you don't know about kinematic bodies in Ammo, the PlayCanvas docs have some info). The PlayCanvas engine codebase shows how kinematic bodies are set up. Ideally, you should ensure the body is configured as follows:

    body.setCollisionFlags(body.getCollisionFlags() | BODYFLAG_KINEMATIC_OBJECT);
    body.setActivationState(BODYSTATE_DISABLE_DEACTIVATION);

@oliverellmers
Copy link
Author

oliverellmers commented Feb 16, 2022

Thaks for the links - sadly I can't quite find any answers to my problem in those above..

I am trying to achieve something that in my mind seems fairly simple -

I have a softbody object anchored in space i would to be able to swipe or hit with my mouse, and it to respond to this.

My thinking here is to have a rigidbox ball be moved around with the mouse, which you can then use to 'hit' the softbody with.

Currently I have a rigib body ball moving around with the mouse, but it doesnt affect any softbody objects in the scene....

function createMouseGeometry(){

              const ballMass = 0;
              const ballRadius = 7;

              ball = new THREE.Mesh( new THREE.SphereGeometry( ballRadius, 18, 16 ), ballMaterial );
		
              ball.castShadow = true;
              ball.receiveShadow = true;
              const ballShape = new Ammo.btSphereShape( ballRadius );
              ballShape.setMargin( margin );
              pos.copy( raycaster.ray.direction );
		pos.add( raycaster.ray.origin );
		quat.set( 0, 0, 0, 1 );
              ballBody = createRigidBody( ball, ballShape, ballMass, pos, quat );
              ballBody.setFriction( 0.5 );
		

              ballBody.setCollisionFlags( 2 );
		scene.add(ball);
	}

			
	// Follows the mouse event
	function onMouseMove(event) {

		mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
		mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
		raycaster.setFromCamera(mouse, camera);
		raycaster.ray.intersectPlane(plane, intersects);

		ball.position.set(intersects.x, intersects.y, intersects.z);

		
		const velocity = new Ammo.btVector3(intersects.x, intersects.y, intersects.z);                
              ballBody.setLinearVelocity(velocity);
              ballBody.needUpdate = true;
              Ammo.destroy(velocity);
		
		
	};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants