I working on a 2d minigame where your can move around platforms and shoot at ennemies
But I can’t find a good “track to mouse” script, because all of them work only in top view and mine is in side view, and so the gun only rotates around Z axis
I want it to rotate around X axis when you move the mouse
This script looks like it is moving an object around under where the mouse is (own.position = mouseover.hitPosition). I would create an empty and attach this code to it. Then track the gun or the arms of your character towards the empty.
Frankly your file was too confusing for me, with all the weird rotations.
The one thing to watch is that the gun will rotate at different speeds depending on where the empty is. If you zoom back you can see the object parented to the empty. The farther away the empty the slower the rotation of the gun.
You could probably get around this by constraining it with .getDistanceTo() function, though.
P.S. Even from just looking at the very beginning of your game it looks like it could be really fun. I look forward to seeing it in the finished games section of the forum.
Hmm… Yes, your file was doing some weird things for me. I would have done the script for your file but I just couldn’t understand what was going on.
I’ll give it a try.
The biggest difference is I was using a Y,Z set up and you had a X,Z set up.
I also changed the always sensor that tracks the gun to the empty. You had it with a frequency. You also had the time set on the track to actuator I changed that to zero. With no frequency set the always sensor fires once. With no time set the track to sensor will always track to the object.