Mouse Cursor Follow Script

Hey everybody, I was just wondering if I could get some scripting help for this small project I’m working on in BGE. The game is a pretty simple shooter game, and I want the gun to follow the mouse cursor around the screen as the player attempts to shoot at enemies. I guess it would be similar to parenting the gun to the mouse cursor, but I know that’s not possible. Any help would be greatly appreciated, and let me know if I can clarify anything about what I’m trying to do!

Sounds like you need a mouse-look script. this script it put on a camera or a parented object with the camera being the child.
Here’s the link to the best one(easiest to understand)
Parent the Gun to the cam or the object with child to the cam and use a python controller…hope this helps :slight_smile:

Yeah I looked into mouse-look scripts, and they’re close to what I’m looking for, but my game uses a fixed camera, so the gun’s movement can’t be reliant upon the movement of the camera. I looked into the script you posted, and it seems like it could be adjusted to work for what I’m trying to do, but I’m still very much a novice at python and wouldn’t even know where to start!

Hey everyone, I know it’s been a while since I’ve posted in this thread (unfortunately its been a while since I’ve been able to spend much time working in Blender as well :(), but I’ve worked on creating a script that allows me to follow the mouse cursor. I feel like it’s close to being operational, but there’s still one problem: the in-game object doesn’t follow the mouse cursor with nearly as much precision as I would like it to. It’s somewhat difficult to explain, so I’ll post an example file below with what I’ve been working on. Any help that you all could offer would be greatly appreciated! :slight_smile:

cursor_follow.blend (510 KB)

one sec example to follow

ok-example up, video soon :smiley:


TracknShoot.blend (444 KB)


Thank you so much for your help! This works exactly how I had wanted it to! I can’t believe how complicated I was making that :o. I just have one question for you though so that hopefully next time I’ll be able to figure something like this out on my own: what made you think to use Mouse Over Any as the Mouse Event? Also, why is it necessary that the ground have a collision box? Once again thank you so much for your help in solving this problem of mine and for replying as quickly as you did! :smiley:

you can cast a ray, from a object that rotates using a mouse aim like script,

or this, which uses mouse.hitPosition to place a track to target , the enemies and the map are used to move the cursor, however you could just use a plane, and have it static ghost, and shoot through it,

No matter what you still need sens.hitObject

so you are going to need a collision mesh to find valid or even invalid targets

valid=spawn blood? add damage?

invalid = spawn bullet strike sparks/dust

Ohhhh, I see! Alright, thank you once again!