How to move the camera and the gun with the mouse at the same time?

Hi guys, i’m making a Sandbox game like GTA, i have all the basic animations but i want to know how to move the gun, that is parented to a bone, with the mouse, at the same time i move the camera with the mouse, what I mean is that when I point my camera at a target, say at the sky, the gun points to the sky too, how I can do this?

You parent the gun and the camera to a third object behind the camera and then use a mouse-look script with a movement sensor and hit pulse at 0. hook that up with a python controller and that should work

So i have to unparent the gun with the arm? then the gun will flotate on the air and the arm will be on it side. EPIC FAIL! lol.
i will try your advice, thanks for reply dan :wink:

Easy solution, parent arms to the camera, parent gun bone to the arms.

So i have to unparent the gun with the arm

arm object not found in first post.

I deduce that OP is making a third person game.

Simply parenting the arms/gun doesn’t give you good results because you will want the arms connected at shoulders.

Ideally you will want a character animation that has frames 0 - 180 where the character aims completely down at frame 0 and completely up at frame 180. Then you can play the relevant animation frame as you aim. Basically get the camera pitch, covert to degrees, add 90 and play that frame from your aim animation.

that’s not a bad idea! now the big question is, how to activate the animation properly? can i do it whit the mouselook? that what i was thinking about it! i actually have that animation! but the problem i see here is that i only want to reproduce that animation while i hit Right mouse button (while i aim) do i have to create another mouse controller or is there a script to get it working properly?
THANKS TO ALL GUYS, i never though i get 3 answers in less than 2 days!!! :slight_smile: i really explained it well this time!!!

You can use Action constraint, Not sure if it runs in the GE though.

Mmmm … i heard that it doesn’t work, but i can try.

I don’t think it’s possible in logic bricks, but in python the outline would be:

  1. Make a new script file and connect it to always and mouse sensor
  2. run a hand adjusting function when mouse2 is positive, later you can add parts about what it should do after user doesn’t press the button anymore and you’ll likely want to revert to standard position
    In the hand adjusting function:
  3. get camera pitch
  4. convert it to degrees
  5. use playAction() or action actuator

Making it requires some python skills but then again so does the game genre you’re doing.

THANKS BUDDY!!! that’s a very reseable answer! HAHA! :slight_smile: if it works, YOU ARE THA MASTER!!! :wink:

hi again guys! is there a script when i can rotate the bone with python? I saw a script to move the bones in rest position, but, how can adjust it to fit with the mouselook script?
this is the code i’m using to move the camera with the mouse
co = bge.logic.getCurrentController()
o= co.owner

mouse = co.sensors[“mousesensor”]

Cube= scene.objects[“Cube”]
cameraTarget= scene.objects[“cameraTarget”]

#####mouse movemente

movSpeed = 0.3
rotSpeed = (0.005, 0.005)

mouse look

x = (render.getWindowWidth() / 2 - mouse.position[0])
y = -(render.getWindowHeight() / 2 - mouse.position[1])

Cube.applyRotation((0 , 0, int(x) * rotSpeed[0]), False)
cameraTarget.applyRotation((int(y) * rotSpeed[1], 0, 0), True)
render.setMousePosition(int(render.getWi*ndowWidth() / 2), int(render.getWindowHeight() / 2))

I don’t recommend rotating the bones with python. Like I said it would be easier to make an action about your character aiming up and down. Why this is is because you’ll likely want to adjust many bones in a rather complex manner as the character aims up and down.

So when you’re aiming up for example you have the character bend at the waist up and also the head should move, plus the arms move and they also depend on the weapon you’re equipping as aiming up/down with say, a handgun is different from assault rifle or grenade.

It is also more WYSIWYG solution and easier to achieve and debug.

So kheetor, how can i get it work properly when i move the mouse up and down?
You’re right whe you say that the pose change from handgun to hold an AK47 or a M14 even a bazuka.