FPS Game Bullet Direction

Hi! I need help on my bullet direction. it just keeps going down when I shoot instead of forward/towards the target. i need to be right beside my object for it to be hit and disappear. Is this a code issue, or a bullet emitter and bullet issue in the scene?

Hoping anyone could help me! It’s a midterm project due on March 1st :frowning:

Hi! What is the rigidbody on the pool? If dynamic, then change to kinematic, gravity can shift the trajectory

entityX. = entityX + (Math.cos(axisX) * 1);/*(number can be changed for bullet speed)*/
entityY = entityY + (Math.sin(axisY) * 1);/*(number can be changed for bullet speed)*/

sorry I commonly forget how to program in PlayCanvas, I do know Javascript though and this is the math to do it, NOW if you want to add the Z axis just copy and paste the Y axis stuff and switch the right code to the Z Position stuff because Z is just the Verticle Y Axis

i tried kinematic and it became an error

thank you so much!! but may i ask someone to convert it into scripts? sorry i’m no programmer at all

I got you

const thisEntity = new pc.Entity();
var bulletSpeed = 1
var rotation = thisEntity.rotation;
var euler = new pc.Vec3();
rotation.getEulerAngles(euler);
thisEntity.x = thisEntity.x + (Math.cos(euler.x) * bulletSpeed);
thisEntity.y = thisEntity.y + (Math.sin(euler.y) * bulletSpeed);

I think this should work, if not than ask a moderator because PlayCanvas may be way more complex than I thought, but normal JS this would work 100% so I’m hoping this will

thank you so much! i put it in the fireBullet code but nothing happened. it didn’t necessarily error either

@DANIELLE_SABINE_LIM I don’t see a link to your project but it sounds like you are firing using physics rather than raycasting. If this is the case then here is a project you could have a look at.

https://playcanvas.com/project/917448/overview/fpstarget

Also, this seems to be a common question on the forum. Here is a search link which may give you more ideas.

https://forum.playcanvas.com/search?q=bullet%20forward

Hope this helps.

hmmm, yeah u need someone more skilled, I don’t fully know how playcanvas works @Tirk182 ?