I use the same script to fire bullets. I got the bullets to move but they move in the wrong direction. They go to the rightside of the gun. I changed this “this.force.copy(gun.forward);” to gun.right and the bullets started to go backwards after i’ve done that. There’s no left or backward parameter available, what should i do?
Hi @Ronin! You can try to use a negative value. For example
-gun.right is left and
-gun.forward is backwards.
bullets’ direction also changes when i change the rotation of the pistol in PC but i can’t get it right. I can’t align the parent camera and pistol’s rotation
no man, -gun.forward or right didn’t work for me. I need to adjust the pistol’s rotation right, that’s the only way
I was more replying on this.
i know. Hey can you take a quick look at why this is happening if i share the link to my project, it’ll just take a sec. I can’t get the rotation of the pistol right. Bullets spawn from the right side of the gun, no matter what i tried , i couldn’t fix it
i think the rotation value of the pistol has to be 0 but when i attach it to camera it changes to -90. Camera and pistol should point the same direction but pistols rotation value has to be 0. How am i gonna do that?
You can share a link of your project if you want someone to take a look.
PlayCanvas | HTML5 Game Engine thanks a lot!!
@Ronin Here is a example that I worked on some time ago. It will give you some basics but by no means is it totally complete. It was kind of a playground for me to experiment.
My workaround will be to parent the gun by an empty entity like below. Here is model your current gun entity.
To get the opposite direction on a vector, you can use the same technique shown here The normalized local space X-axis vector of the graph node in world space
In your project all of your player->Camera->Handgun objects have the rotation values of 0. We use the same shoot function for shooting bullets
// var bulletRotation = player.getRotation(); // bullet.setRotation( bulletRotation ); // bullet.rotateLocal(90,0,0);
These are commented out in my script but it didn’t change anything when i activate them anyway. I also changed the values of bullet.rotateLocal(90,0,0); nothing changed. Only code that changed the bullet’s direction was “this.force.copy(gun.forward);” when i changed the gun.forward to gun.right bullets started to go backwards. I tried “-gun.forward” and “-gun.right” and when i did that i didn’t even see the bullets coming out of the pistol
It worked. Thanks a million for the help
Thanks to all of you
@Ronin Yes I understand the confusion over this. As I stated before this was kind of a playground for me at the time. It’s my bad for throwing something out there that was at the time experimental. I have since then learned much more about the Playcanvas system. Let me explain why I did this. @yaustar (this probably needs to be moved to a new thread maybe).
In the beginning I used a nerf bullet asset that was obtained from a free online asset store. The bullet itself was in an upright position. I could have brought the bullet into Blender and adjusted it’s angle. Or I could have rotated it in the settings of Playcanvas. Instead I changed the angle so it would point forward programatically.
There was a reason to do it in software. What I was planning on doing was using different types of projectiles like arrows or what ever free item I could locate. This way I had control of changing it with an attribute rather than changing code all the time. In my example I changed it to a simple cylinder for test. If you enable the object in the example provided you will see the angle is incorrect in the start state.
This works in my example. But, if I remember correctly you had used a sphere of which no matter what you do to the rotation, doesn’t really visually effect anything when rotating.
I apologize again for the rushed example.
@Ronin As far I can see, the script you use from the other topic doesn’t use the forward direction of the gun to apply the force. That means you basically can apply the force on another axis, to get the right direction. Then you don’t need my workaround.
what does it use then, this: “bullet.rigidbody.applyImpulse(this.force);”? But the direction of the bullet changed when i changed gun.forward to gun.right
As far I can see, the script use the way below.
bullet.rigidbody.applyImpulse(0, 0, -500);
If that’s the case, you can try to apply a negative or positive force on another axis, like below.
bullet.rigidbody.applyImpulse(0, 500, 0);
ah no in my script that part was different, it was like this “bullet.rigidbody.applyImpulse(this.force);”