0
$\begingroup$

I have a custom cursor, I need it for moving crosshairs. I have a moving ship that is only controlled with the keyboard, but in front of it are 2 empties. When I press the assigned key/button, 2 bullets come out. It works great. I also have it so that these empties turn when I move the mouse. Mouse/mouse movement - and - mouse/look. It works when firing the guns, I can move the mouse and the guns move. The problem that I am having, however, is that the cursor and the line of sight for the bullets don't line up. If I press the "reset" on the mouse/look actuator, the cursor will stay in the center while the bullets aim and move around freely. If I click off on the "reset" on the mouse/look actuator, it's better, but the cursor doesn't align to where I'm shooting. I can kind of fix this by forcing the cursor to the side, and it centers both of them for a little while, but after a minute or so, the two become separated once again. Is there a way to fix this?

This is how I have it set up right now:

Here's how the empty is set up for firing the guns: logic bricks

Here's how the cursor scene is set up, which needless to say is overlayed: BGE and python script

And this is what it's doing. Notice how the cursor is near center, but the bullets are firing off to the side?

problem in game

Basically, I want to know how do I link up the bullet line of sight with the custom cursor?


Update I have found a script that centers (well, a little off from center but that's preferable for me) the mouse upon starting.

import bge

bge.render.setMousePosition(int(bge.render.getWindowWidth() / 2.003), int(bge.render.getWindowHeight() / 3))

Sadly, the empties do not align to center the way that I want it to still. It still makes them shoot off to the side. Is there a way to fix this?

$\endgroup$
  • $\begingroup$ With mouse look (function, script), the mouse stay almost in the center of screen and slightly add it movement to the vector where supposed you aim every frame and then the mouse is set to the center of screen and calculated movement again. That's why it never alling with watever you are pointing. $\endgroup$ – Strapicarus Aug 20 '17 at 10:28
  • $\begingroup$ This answer I wrote a while back might be of some help to you. $\endgroup$ – David Sep 30 '17 at 13:54
0
$\begingroup$

According to the description you really want to let the ship fire projectiles toward a point under the system mouse cursor.

I suggest to use a short Python script to position an "aiming target" empty at the desired location (e.g a collision point under the cursor). Then let the turrets turn towards that aiming target (TrackToActuator).

Setting the system mouse cursor to the middle of the screen at game start would still add to the player's comfort.

$\endgroup$
  • $\begingroup$ I'm not very good with coding yet, so how would I go about doing that? $\endgroup$ – Mechaghostman2 Aug 21 '17 at 16:49
  • 1
    $\begingroup$ nvm I just put a completely invisible cursor in front of my ship, and tracked the turrets to it. It works great now. :) $\endgroup$ – Mechaghostman2 Aug 21 '17 at 18:36
  • $\begingroup$ @Mechaghostman2 could you share the solution and the script? maybe I will use your solution to adjust my multiple selector of objectives, which I will share if I manage to make it work correctly $\endgroup$ – user52476 Feb 20 '18 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.