Gun.Rotation = New Vec3f( -Mouse.Y, -Mouse.X,0)

About Monkey 2 Forums Monkey 2 Programming Help Gun.Rotation = New Vec3f( -Mouse.Y, -Mouse.X,0)

This topic contains 1 reply, has 2 voices, and was last updated by  Ethernaut 6 months, 1 week ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #15838


    I have my gun on screen. How do I clamp the values of Mouse.X/Y to only allow a certain amount of rotation? Also, How can I centre the mouse onscreen so that even if the mouse reaches the end of desktop width it still applies motion to the 3d world?



    You need to compare the current mouse coordinates with the coordinates in the previous frame (stored in a variable), and only apply that difference multiplied by a “mouseSensitivity” variable. If you’ve already reached the rotation you want to limit to, don’t rotate anymore! (something like: If Entity.Rotation.Y < limit Then RotateFunctionGoesHere() )

    Not on my laptop, but you can specify the mouse coordinates using Mouse.Location = New Vec2f, I think.
    My old code that handles first person mouse look is this (out of context):

    And at the end of the update, it resets the mouse location like this:

    I’m in the process of cleaning up and rewriting a CharacterController component that can be used in first person games, but the old version is here:


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.