Home Unreal Engine

Custom mouse behaviour

Hi all, i'm in trouble again :(

I solved my problem with the camera but now i'm dealing with mouse movements:
first off i need to disable the mouse (i won't need it 'cause i'm moving with arrow keys and my point of view has to remaing still while moving).

Than i need to toggle the mouse ON while i'm standing still, to look around by using the right mouse button.

...AND...after looking around with mouse, i need the camera view to return to a certain position...

let's have a look at this image :

[IMG][/img]mah.jpg


...zomfg...what i-m looking at?


relax lol, let's say i'm standing in a square, because my world is made of squares only: since my camera is moving by steps of 90 degrees (like a boardgame when i move, i jump from the center of a square to another, like...a chesspiece?) i named the adjacent squares 0 -90 +90 180. if i start looking around using the mouse, my viewpoint will move freely ignoring the squares, that's fine BUT... when i stop looking around (in other words when i release the right mouse button) and i'm ready to move, i need the camera to slowly reallign to a square, because as i said above i can only move to the center of a square to another, so i have to be alligned...

so, according to the image i need some way to realize WHERE i'm looking and what's the closest way to allign the camera.

so, the camera is standing at the center of a sqare, and with some diagonal lines i limit an area of influence for each of the close squares, all those arrows are just there to tell in which direction the viewpoint has to move in order to reallign with a square.

example: the player is standing at the center of a square and looking UP , like the image, let's say that when i release the right mouse button my view is slightly moved on the right (without crossing to top-right diagonal line) the camera will slowly move left to return to the initial position, the same situation you see in the image....

example 2: the player is standing at the center of a square and looking UP , like the image, let's say that when i release the right mouse button my view point has moved right and CROSSED the top-right diagonal line, the camera will now allign with the +90 square because it is the closest one.

i just hope it makes any sense to you, i actually don't know how to proceed, and whats the better approach, kismet or scripting (i actually suck with both lol): sorry for the bad english, perhaps i could have explained all with half of the words that i used ehehe

any ideas?

thanks in advance.

Replies

  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    Scripting is likely the best way.

    set up a state machine.
    Have a state for moving and for standing still.
    When transitioning from moving to standing, or vice versa, store the heading you want to return to in a variable (like say var vector3 LastHeading)
    In the moving state, the function for looking around always returns LastHeading, but when standing it allows the mouse to do its normal freelock behaviour.

    To get the above quadrants, the fastest way would be comparing 2 dot products.
    You'll want to create 2 vectors representing the 45 degree lines. Start with LastHeading, rotate it 45 degrees about the z axis so it aligns with the line between 0 and 90 (we'll call this A), then create a second vector 90 degrees from that rotated one (simple way, set the new vector to equal A.y, -A.x, A.z). (we'll call that B)

    Then take the dot product of the look direction with A and B, and it will tell you what heading to snap to.
    View direction = V
    VdotA >0 and VdotB <0 = New Look Direction 0
    VdotA & Vdot B >0 = new look direction 90

    Vdot A <0 and VdotB > 0 = New look direction 180
    VdotA and V Dot B <0 = New Look Direction -90

    The directions to look can be found from the stored LastHeading and simple math.
    L = last heading
    0 = L
    90 = (L.y, -L.x, L.z)
    180 = -L
    -90 = (-L.y, L.x, L.z)

    Smoothing the cam into them is just changing the angle of the view till it matches the desired look direction over time. There should be some lookat function defined somewhere, or I'm sure you can find one. :)
  • SkyNet00
Sign In or Register to comment.