# Targeting a mouse click?

Okay so I have this game I’m working on, it’s a side-scroller and when the player clicks on the screen the player’s character fires a bullet(s) at that point on the screen. (Using X and Y coordinates)
I know how to get the player’s location (point A), and the location of the mouse click (point B).

But now what? What is the best way to physically move the bullet from point A to point B?

I’ve tried using a physics control, a custom control, and I’m currently working on a character control, but so far the only one that works has been the physics control (which is based off the Hover Tank test) but I don’t want the bullets to be affected by gravity (I’ve tried setting gravity to 0, but then they just float away when I try to shoot downward), I just want them to travel in a straight line until they either hit something (wall, floor, etc.) or reach point B. I’ve gone through the tutorials several times now, read the forums, and read the math for dummies multiple times as well, but there’s something I seem to be missing.

The mouseClickLocation and playerLocation are Vector3f’s:

[java]Vector3f chargeTarget = mouseClickLocation.subtract(playerLocation).normalize();[/java]

I think is that. Hope i helped!

My question was more about how to move the bullet’s spatial in that direction.

Okay, so after working some more on my code, I think I actually know less than I did before…
I’m using a custom control, and I’ve run into two problems:

1.) My understanding of how to get the mouse (x,y) coordinates is way off. I’ve found several different methods for getting the direction the bullet should travel, none of which appear to actually work for me. They are:

[java] // Method 1
Vector2f click2d = inputManager.getCursorPosition();
System.out.println("click2d = " + click2d);
Vector3f click3d = cam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f).clone();
System.out.println(“click3d = " + click3d);
Vector3f dir = cam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f).subtractLocal(click3d).normalizeLocal();
System.out.println(“dir = " + dir);
System.out.println(””);

``````    // Method 2
Vector2f mouse = inputManager.getCursorPosition().normalizeLocal();
System.out.println("mouse = " + mouse);
Vector2f origin = new Vector2f(armModel.getWorldTranslation().x + .5f, armModel.getWorldTranslation().y);
System.out.println("origin = " + origin);
Vector2f target = mouse.subtract(origin).normalize();
System.out.println("target = " + target);
Vector3f dir2 = new Vector3f(target.x, target.y, 0);
System.out.println("dir2 = " + dir2);
System.out.println("");
float distance1 = origin.distance(mouse);
System.out.println("Distance from origin to mouse: " + distance1);

//Method 3
Vector3f loc = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.0f);
System.out.println("loc = " + loc);
Vector3f dir3 = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.3f);
System.out.println("dir3 = " + dir3);
dir3.subtractLocal(loc).normalizeLocal();
System.out.println("dir3 now = " + dir3);
System.out.println();

// Mehtod 4
Vector2f m = inputManager.getCursorPosition();
System.out.println("m = " + m);
Vector3f playerPos = player.getLocalTranslation();
System.out.println("playerPos = " + playerPos);
Vector3f dif = new Vector3f(m.x-playerPos.x,m.y-playerPos.y,0);
System.out.println("dif = " + dif);

// Method 5 -- uses origin from Method 2.
Vector3f loc2 = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0);
Vector3f path = new Vector3f(loc2.x-origin.x,loc2.y-origin.y,0);
System.out.println("path = " + path);[/java]
``````

Having the player stand at (0,1,0) and target (mouse click) at (6,1,0), I get the following results:

Method 1 click2d = (543.0, 265.0) click3d = (0.3848734, 0.6931473, 14.0) dir = (0.0, 0.0, 0.0)

Method 2
mouse = (0.89868885, 0.43858665)
origin = (0.5, 0.65)
target = (0.88347363, -0.46848089)
dir2 = (0.88347363, -0.46848089, 0.0)
Distance from origin to mouse: 0.4512742

Method 3
loc = (-0.5507337, 0.23654345, 14.0)
dir3 = (-0.7864253, 0.059600804, 13.572041)
dir3 now = (-0.45358157, -0.34052092, -0.8235954)

Method 4
m = (0.89868885, 0.43858665)
playerPos = (0.0, 0.65, 0.0)
dif = (0.89868885, -0.21141332, 0.0)

Method 5
path = (-1.0507337, -0.41345653, 0.0)

None of these actually send the bullet in the right direction, nor do they seem to get the actual world coordinates of where the mouse was clicked (unless I’m missing something).
Can anyone tell me which (if any) of these are actually correct? Is there some conversion I’m not using to get the actual world coordinates of part of the screen I clicked on?

Also, my second problem is:
2.) At the moment, the controlUpdate() method for my control consists of:

[java] @Override
protected void controlUpdate(float tpf)
{
if(spatial != null)
{
//System.out.println(“moving to :” + dir);
spatial.move(dir.multLocal(speed*tpf));

``````    }
//System.out.println("x = " + spatial.getWorldTranslation().x + " y = " + spatial.getWorldTranslation().y + " z = " + spatial.getWorldTranslation().z);
}[/java]
``````

Is this incorrect? Because when I attempt to fire a bullet, the bullet will appear at a random point (usually at the origin), but then moves slightly in a straight line away from the player whenever I click the mouse again.

Once again, any help is appreciated.

It’s definitely clear that you are flailing about: Unfortunately, you haven’t told us how your scene is constructed so any answer I give would be random. If your game is essentially 2D then all of this is way more work than required. If it’s 3D then some of your attempts were almost half right.

Sorry, it is in fact a 3D game, the player moves horizontally along the X-axis. (Z-axis is pretty much 0 for everything)

As for normalizing location, that didn’t seem to makes sense to me either, but several of the methods used normalize and normalizeLocal, so I tried switching the two around (as well as not using either) when it didn’t work and just forgot to change them back before posting the code.

And yes, the player is in the player node, and armModel (also in the player node) is the player’s arm. It’s separate because I want the player’s arm to rotate to point at where the mouse was clicked. (Haven’t implemented that part yet though)

Well, if you already know what left/right/up/down are then you could just find the player’s location on screen and use the screen vector for motion.

Alternately, you could use get world coordinates but you should pass the Z of the player as the last parameter (not 0, not 0.3, etc.). Make sure the z value is camera relative and that you run it through http://hub.jmonkeyengine.org/javadoc/com/jme3/renderer/Camera.html#getViewToProjectionZ(float) to get the value in homogenous space.

(Assuming your camera points down the negative Z-axis)
relativeZ = cameraLoc.z - playerLoc.z;
…or to be safe:
relativeZ = Math.abs(cameraLoc.z - playerLoc.z);
…and for the record if you wanted the view independent Z distance that would work even in real 3D:
relativeZ = camera.getDir().dot(playerLoc.subtract(cameraLoc));

projectionZ = camera.getViewToProjectionz(relativeZ);

…and pass that as the last parameter to getWorldCoordinates().

1 Like

Well, it appears to be working, except the bullet only moves when I click the mouse (it moves one increment per click). Here’s my control’s code:

[java]public class bltControl extends AbstractControl
{
private static Vector3f dir = new Vector3f();
private float speed = 500f;

``````//public Shifter(){} // empty serialization constructor

public bltControl(Vector3f dir)
{
this.dir = dir;

}

@Override
public void setSpatial(Spatial spatial)
{
super.setSpatial(spatial);
}

@Override
protected void controlUpdate(float tpf)
{
if(spatial != null)
{
//System.out.println("moving to :" + dir);
spatial.move(dir.multLocal(speed*tpf));
//spatial.move(dir.multLocal(tpf).x, dir.multLocal(tpf).y, 0);
//spatial.move(dir);
}
//System.out.println("x = " + spatial.getWorldTranslation().x + " y = " + spatial.getWorldTranslation().y + " z = " + spatial.getWorldTranslation().z);
}

@Override
protected void controlRender(RenderManager rm, ViewPort vp){
/* Optional: rendering manipulation (for advanced users) */
}
``````

}[/java]

And I call it using: [java]bullet.addControl(new bltControl(target));[/java]

I’ve used other custom controls this way, and all of them function properly, I’m not sure if there’s something wrong with my Spatal.move() (Again, this is something I found used in several examples and forums) or if I just messed something up somewhere and can’t see it myself.

Also please note, when I say it “appears” to work, I mean clicking the mouse button really fast causes the bullet to move towards the mouse cursor, unfortunately, changing the location of the mouse cursor will cause the bullet to redirect itself towards the new location.

Thank you for your help so far, I’m still getting used to programming in a 3D environment, all of my graphics-related programming involved swing and jOptionPane before I started using jMonkey. I hope this is the last issue I have to trouble you guys with.

Clicking the mouse causes it to move… but we can’t see that code so we can’t see that you are probably resetting the direction to zero on mouse up or something. Your mouse handling is the missing piece.

Okay, so here’s my code for handling the mouse action:

[java] private void initMouse()
{
inputManager.addMapping(“Shoot”, new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); // trigger 2: left-button
}

``````/** Defining the "Shoot" action: Determine what was hit and how to respond. */
private ActionListener actionListener = new ActionListener()
{
public void onAction(String name, boolean keyPressed, float tpf)
{
if (name.equals("Shoot") &amp;&amp; !keyPressed)
{
shoot();
}
}
};

private void shoot()
{
Vector2f origin = new Vector2f(armModel.getWorldTranslation().x + .5f, armModel.getWorldTranslation().y);

// Player's location
Vector3f pOrigin = new Vector3f(armModel.getWorldTranslation().x + .5f, armModel.getWorldTranslation().y, armModel.getWorldTranslation().z);
// Relative Z
float z = Math.abs(cam.getLocation().z - armModel.getLocalTranslation().z);
// Projection Z
float projZ = cam.getViewToProjectionZ(z);
// Mouse click coordinates:
Vector3f mouse = cam.getWorldCoordinates(inputManager.getCursorPosition(), projZ);
// Direction to move:
Vector3f target = mouse.subtract(pOrigin);

Vector3f sOrigin = cam.getScreenCoordinates(player.getWorldTranslation());
Vector3f sDir = mouse.subtract(sOrigin);
System.out.println("sOrigin = " + sOrigin);
System.out.println("sDir = " + sDir);

Bullet bullet = new Bullet(assetManager, target, origin);

rootNode.attachChild(bullet.getBullet());

}[/java]
``````

And the code for the bullet object:

[java] public Bullet(AssetManager manager, Vector3f target, Vector2f origin)
{
this.target = target;
this.origin = origin;
this.manager = manager;
bNode = new Node();
initBullet();
}

``````private void initBullet()
{
Sphere b = new Sphere(30, 30, 0.5f);
Geometry bullet = new Geometry("Bullet", b);
Material b_mat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
b_mat.setColor("Color", ColorRGBA.White);
bullet.setMaterial(b_mat);
bullet.scale(0.2f);
bullet.rotate(0, FastMath.PI, 0);
bullet.updateGeometricState();

BoundingBox box = (BoundingBox) bullet.getWorldBound();
final Vector3f extent = box.getExtent(null);

bullet.setName("Bullet");
//bullet.rotate(rot);
bullet.setLocalTranslation(origin.x, origin.y + .5f, 0);

bNode.attachChild(bullet);

}

public Node getBullet()
{
return bNode;
}
``````

}[/java]

What happens when you put your debug printlns back in?

The S.O.P lines in the controlUpdate() will continuously print new lines as long as the bullet is active.
The output looks like this:

moving to : (0.0, 0.0, 0.0) x = 14.519913 y = 29.319788 z = 1.1445418E-4

moving to : (0.0, 0.0, 0.0)

…do dir is 0,0,0.

…which I guess must mean that
mouse.subtract(pOrigin);

…is also 0,0,0

0,0,0 is not a direction, exactly. It’s a “no direction”… so it’s not surprising that the bullet doesn’t move. Any movement you see must be caused by the initial offset I guess.

It occurs to me that stepping through in a debugger or simply adding more debug printlns would be infinitely more productive than the forum in this case. It’s not a JME problem but some logic problem in your code that you will have to track down.

My mistake, there was more to it, here’s the full output (sorry I didn’t see it earlier):

moving to : (4.729442, 0.4142139, 1.4305103E-5) x = 3.5146217 y = 1.4140265 z = 9.118301E-6 moving to : (3.0146217, 0.26402655, 9.118301E-6) x = 13.40416 y = 2.2801719 z = 3.9031103E-5 moving to : (9.889538, 0.8661453, 2.99128E-5) x = 23.90548 y = 3.1998982 z = 7.0794355E-5 moving to : (10.50132, 0.9197264, 3.176325E-5) x = 30.1007 y = 3.742488 z = 8.953299E-5 moving to : (6.195222, 0.5425898, 1.8738634E-5) x = 32.298378 y = 3.934965 z = 9.618028E-5 moving to : (2.1976774, 0.19247694, 6.6472962E-6) x = 33.14142 y = 4.0088 z = 9.873021E-5 moving to : (0.8430389, 0.07383502, 2.5499328E-6) x = 33.49762 y = 4.039997 z = 9.9807614E-5 moving to : (0.35620165, 0.031196848, 1.0774002E-6) x = 33.672115 y = 4.0552797 z = 1.00335405E-4 moving to : (0.17449462, 0.015282586, 5.2779245E-7) x = 33.759945 y = 4.062972 z = 1.00601064E-4 moving to : (0.08783134, 0.0076924437, 2.6566275E-7) x = 33.801582 y = 4.066619 z = 1.00727004E-4 moving to : (0.04163671, 0.003646626, 1.2593823E-7) x = 33.82212 y = 4.068418 z = 1.00789126E-4 moving to : (0.020539263, 0.0017988697, 6.2124954E-8) x = 33.8314 y = 4.0692306 z = 1.008172E-4 moving to : (0.009279948, 8.127563E-4, 2.8068987E-8) x = 33.83578 y = 4.069614 z = 1.00830446E-4 moving to : (0.0043793465, 3.8355187E-4, 1.3246176E-8) x = 33.838226 y = 4.069828 z = 1.00837846E-4 moving to : (0.0024459285, 2.1421927E-4, 7.3981807E-9) x = 33.840347 y = 4.070014 z = 1.0084426E-4 moving to : (0.0021207815, 1.8574223E-4, 6.4147105E-9) x = 33.84121 y = 4.0700893 z = 1.0084687E-4 moving to : (8.616099E-4, 7.5461496E-5, 2.6061044E-9) x = 33.84151 y = 4.0701156 z = 1.0084778E-4 moving to : (3.0140835E-4, 2.639794E-5, 9.116674E-10) x = 33.841618 y = 4.070125 z = 1.00848105E-4 moving to : (1.08596665E-4, 9.511111E-6, 3.2847147E-10) x = 33.841667 y = 4.0701294 z = 1.0084826E-4 moving to : (5.0691076E-5, 4.4396247E-6, 1.533249E-10) x = 33.841686 y = 4.070131 z = 1.00848316E-4 moving to : (1.9022587E-5, 1.6660358E-6, 5.7537468E-11) x = 33.841694 y = 4.0701313 z = 1.0084834E-4 moving to : (7.1669874E-6, 6.2769897E-7, 2.167793E-11) x = 33.841698 y = 4.070132 z = 1.00848345E-4 moving to : (3.0511906E-6, 2.6722932E-7, 9.228912E-12) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.5149313E-6, 1.326807E-7, 4.582201E-12) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (7.6124087E-7, 6.667099E-8, 2.3025193E-12) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.8691206E-7, 3.388653E-8, 1.1702899E-12) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.8424423E-7, 1.6136477E-8, 5.572821E-13) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (8.541111E-8, 7.480475E-9, 2.583423E-13) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.8973557E-8, 3.4133816E-9, 1.1788301E-13) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.538376E-8, 1.3473402E-9, 4.6531135E-14) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.1545917E-8, 1.8870343E-9, 6.5169766E-14) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.2828104E-8, 1.9993307E-9, 6.9047985E-14) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.8641497E-8, 1.6326593E-9, 5.6384788E-14) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.0252105E-8, 8.978997E-10, 3.100946E-14) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.9349475E-9, 3.4463052E-10, 1.1902005E-14) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.5490098E-9, 1.3566535E-10, 4.6852776E-15) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (6.3296024E-10, 5.5435916E-11, 1.9145098E-15) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.7380023E-10, 2.3979969E-11, 8.281614E-16) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.2423398E-10, 1.0880659E-11, 3.7576954E-16) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (5.8362204E-11, 5.1114776E-12, 1.7652769E-16) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.676425E-11, 3.219886E-12, 1.1120054E-16) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.7656177E-11, 1.546363E-12, 5.3404498E-17) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (8.335984E-12, 7.30082E-13, 2.5213784E-17) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (4.0764714E-12, 3.5702544E-13, 1.233007E-17) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.9542542E-12, 1.7115745E-13, 5.911017E-18) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (9.418811E-13, 8.2491814E-14, 2.8489004E-18) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (5.5908365E-13, 4.8965653E-14, 1.6910559E-18) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (5.457313E-13, 4.779623E-14, 1.6506691E-18) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.1833044E-13, 1.9121813E-14, 6.6038233E-19) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (8.622677E-14, 7.551912E-15, 2.6080943E-19) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.407259E-14, 2.9841456E-15, 1.03059105E-19) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.4906367E-14, 1.3055293E-15, 4.5087172E-20) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (7.213027E-15, 6.3173125E-16, 2.1817186E-20) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.4301512E-15, 3.0041948E-16, 1.0375152E-20) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.6612788E-15, 1.454981E-16, 5.0248573E-21) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (8.1097894E-16, 7.1027154E-17, 2.4529617E-21) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (4.0664344E-16, 3.5614645E-17, 1.2299712E-21) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.1155197E-16, 1.8528144E-17, 6.398796E-22) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.08972E-16, 9.543985E-18, 3.2960674E-22) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (5.4314803E-17, 4.756999E-18, 1.6428556E-22) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.7304377E-17, 2.391372E-18, 8.258734E-23) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.4309895E-17, 1.2532893E-18, 4.328303E-23) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (9.054043E-18, 7.9297116E-19, 2.7385694E-23) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (8.766178E-18, 7.677594E-19, 2.6514994E-23) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.7207647E-18, 3.2587202E-19, 1.125417E-23) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.5927868E-18, 1.3949946E-19, 4.8176907E-24) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (8.1739114E-19, 7.1588753E-20, 2.472357E-24) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (4.1772362E-19, 3.6585074E-20, 1.2634856E-24) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.1204655E-19, 1.8571463E-20, 6.413756E-25) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.0918138E-19, 9.562325E-21, 3.3024013E-25) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (5.43958E-20, 4.7640934E-21, 1.6453057E-25) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.109035E-20, 2.7229554E-21, 9.403876E-26) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.6719566E-20, 1.4643332E-21, 5.0571552E-26) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (8.065393E-21, 7.0638336E-22, 2.4395337E-26) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.5509385E-21, 3.1099833E-22, 1.0740498E-26) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.5390691E-21, 1.3479476E-22, 4.655211E-27) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (6.927419E-22, 6.067172E-23, 2.0953313E-27) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (4.4230565E-22, 3.8738015E-23, 1.3378387E-27) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.5658636E-22, 2.2472347E-23, 7.760949E-28) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.799756E-22, 2.4520823E-23, 8.468402E-28) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.405658E-22, 1.2311034E-23, 4.2516834E-28) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (6.672581E-23, 5.84398E-24, 2.0182507E-28) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.3771732E-23, 2.957796E-24, 1.0214911E-28) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.651507E-23, 1.4464228E-24, 4.9953007E-29) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (8.397565E-24, 7.3547553E-25, 2.5400052E-29) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (4.1029953E-24, 3.5934855E-25, 1.24103E-29) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.0020647E-24, 1.7534485E-25, 6.0556304E-30) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (9.537947E-25, 8.353525E-26, 2.8849357E-30) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (4.662215E-25, 4.0832615E-26, 1.4101767E-30) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.239047E-25, 1.9610025E-26, 6.7724297E-31) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.140902E-25, 9.992249E-27, 3.450878E-31) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (5.9988515E-26, 5.2539145E-27, 1.8144682E-31) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.499238E-26, 3.0647029E-27, 1.0584119E-31) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.5783979E-26, 2.2582126E-27, 7.798861E-32) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.4390804E-26, 2.1361955E-27, 7.3774684E-32) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.074893E-26, 9.414128E-28, 3.2512208E-32) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (4.8979002E-27, 4.2896787E-28, 1.4814642E-32) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.3962214E-27, 2.0986587E-28, 7.247833E-33) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.1846117E-27, 1.0375066E-28, 3.583086E-33) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (5.722077E-28, 5.0115096E-29, 1.7307523E-33) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.7027771E-28, 2.3671464E-29, 8.17507E-34) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.3026427E-28, 1.1408805E-29, 3.9400936E-34) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (6.1390094E-29, 5.376667E-30, 1.8568616E-34) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.0638016E-29, 2.6833386E-30, 9.2670574E-35) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.4425772E-29, 1.2634379E-30, 4.363352E-35) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (6.7768886E-30, 5.935334E-31, 2.0498001E-35) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.6155842E-30, 2.2907806E-31, 7.911337E-36) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.0766149E-30, 9.4292074E-32, 3.2564286E-36) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (4.590357E-31, 4.0203264E-32, 1.3884418E-36) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.472499E-31, 2.1654641E-32, 7.478549E-37) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.1988033E-31, 1.9257558E-32, 6.6507038E-37) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.0211924E-31, 8.943807E-33, 3.088793E-37) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.9500895E-32, 3.4595673E-33, 1.1947806E-37) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.7179847E-32, 1.50464535E-33, 5.1963757E-38) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (6.880469E-33, 6.026052E-34, 2.0811303E-38) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.7055825E-33, 2.369603E-34, 8.183555E-39) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.0349813E-33, 9.0645727E-35, 3.130501E-39) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (4.02335E-34, 3.5237303E-35, 1.21694E-39) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.8092078E-34, 1.5845404E-35, 5.4723E-40) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (8.031137E-35, 7.0338306E-36, 2.42916E-40) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.2250313E-35, 2.824547E-36, 9.7547E-41) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.2385153E-35, 1.0847165E-36, 3.7461E-41) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (5.4289576E-36, 4.7547895E-37, 1.642E-41) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.0825726E-36, 1.8239587E-37, 6.299E-42) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (7.699385E-37, 6.743275E-38, 2.329E-42) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.1247375E-37, 2.7367076E-38, 9.46E-43) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.485969E-37, 1.3014412E-38, 4.5E-43) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (6.4405757E-38, 5.640784E-39, 1.95E-43) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.926475E-38, 2.563065E-39, 8.8E-44) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.3178048E-38, 2.02998E-39, 7.0E-44) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (9.277779E-39, 8.12567E-40, 2.8E-44) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.459809E-39, 3.03017E-40, 9.8E-45) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.262835E-39, 1.10602E-40, 4.2E-45) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (5.08732E-40, 4.4556E-41, 1.4E-45) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.33552E-40, 2.0455E-41, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.07121E-40, 9.382E-42, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (4.959E-41, 4.343E-42, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.4357E-41, 2.133E-42, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.2193E-41, 1.068E-42, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (5.347E-42, 4.68E-43, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.231E-42, 1.95E-43, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.735E-42, 2.38E-43, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.602E-42, 1.4E-43, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (7.85E-43, 6.9E-44, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (4.7E-43, 4.1E-44, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (4.37E-43, 3.8E-44, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.81E-43, 1.5E-44, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (8.1E-44, 7.0E-45, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (3.6E-44, 2.8E-45, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.5E-44, 1.4E-45, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (7.0E-45, 0.0, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (4.2E-45, 0.0, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (5.6E-45, 0.0, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (2.8E-45, 0.0, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (1.4E-45, 0.0, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (0.0, 0.0, 0.0) x = 33.841698 y = 4.070132 z = 1.0084835E-4 moving to : (0.0, 0.0, 0.0)

Once it hits moving to : (0.0, 0.0, 0.0), it just stays there, I’m afraid I don’t understand why the values for ‘dir’ are decreasing like that.
‘dir’ is a Vector3f which isn’t being modified directly, is it because ‘spatial’ is moving?

Nevermind, I fixed the not moving part by changing multLocal(tpfspeed) to mult(tpfspeed), I’m not entirely sure how that works out though.

I’m still having a problem with bullets changing direction if click in a new location after shooting. (The bullets will move towards the new mouse click)

@MKthot said: Nevermind, I fixed the not moving part by changing multLocal(tpf*speed) to mult(tpf*speed), I'm not entirely sure how that works out though.

I’m still having a problem with bullets changing direction if click in a new location after shooting. (The bullets will move towards the new mouse click)

multLocal was modifying the direction vector each time you called it… but you didn’t want to modify the original direction vector or the direction would get super short, super fast.

Regarding your new problem, now you will have to debug to figure out where you are somehow sharing state that you shouldn’t be.