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$
2
  • $\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$ Commented Aug 20, 2017 at 10:28
  • $\begingroup$ This answer I wrote a while back might be of some help to you. $\endgroup$
    – David
    Commented Sep 30, 2017 at 13:54

1 Answer 1

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$
3
  • $\begingroup$ I'm not very good with coding yet, so how would I go about doing that? $\endgroup$ Commented Aug 21, 2017 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$ Commented Aug 21, 2017 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
    Commented Feb 20, 2018 at 17:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .