How to aim the bullet correctly in Jbullet

Post Reply
longboy9977vn
Posts: 2
Joined: Wed Feb 05, 2020 3:52 pm

How to aim the bullet correctly in Jbullet

Post by longboy9977vn »

Im trying to implement jbullet in java, im facing a problem is, how to make capsule bullet correct way to the enemies.
I have try this solution [url]https://stackoverflow.com/questions/117 ... nother[url]
but it seem like not work at all
Screen Shot 2020-02-05 at 22.54.49.png
Screen Shot 2020-02-05 at 22.54.49.png (34.5 KiB) Viewed 758 times
i have try solution in this topic
[url] viewtopic.php?t=10443[url]
but it seem like some func not included in jbullet
like this

Code: Select all

btVector3 currentLook = rotation * localLook;
    btScalar angle = currentLook.angle(newLook);
thank you for your helping me in this, my english is bad so forgive me please
longboy9977vn
Posts: 2
Joined: Wed Feb 05, 2020 3:52 pm

Re: How to aim the bullet correctly in Jbullet

Post by longboy9977vn »

For some one who faced with problem like this i have answer here

Code: Select all

//JBULLET
shootBoxShape = new CapsuleShapeX(0.3f,0.5f);
Vector3f forward = new Vector3f(1,0,0);
Vector3f alignBullet = new Vector3f(destination.x - fromDestination.x, destination.y - fromDestination.y, destination.z - fromDestination.z);
Quat4f  q = startTransform.getRotation(new Quat4f());
			Vector3f CossVec = new Vector3f();
			CossVec.cross(forward,alignBullet);
			q.x = CossVec.x;
			q.y = CossVec.y;
			q.z = CossVec.z;
			q.w = (float) (Math.sqrt((forward.lengthSquared()) * (alignBullet.lengthSquared())) + forward.dot(alignBullet));
			q.normalize();
			startTransform.setRotation(q);
Post Reply