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 · 3 comments
Open

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

oliverellmers opened this issue Feb 16, 2022 · 3 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);
		
		
	};

@suddenly4
Copy link

suddenly4 commented Dec 18, 2024

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....

  1. There is an option(ray + sphere collider)
    https://github.com/aprilonian/artsite/blob/main/src/threejs/scene/skirtgospinny_1.html

  2. There is an option to create a duplicate collider for a soft body (ghost) and get the points and collision force of the soft and hard body via a callback.

  3. There is an option to get touch points using a ray
    https://jsfiddle.net/suddenly4/xp9kc056/1/
    then defrom mesh attribte and update phys shape (rebuild transform), or deform points soft body by node.get_m_x()

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

3 participants