Lerp Camera and Mouse Look

0 favourites
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hi dop2000 sorry to call you out! but you helped me a while back with the Gamepad R-stick to modify the camera to look around.

    So now I'm trying something similar with the mouse. But I need some suggestions since the mouse is so different from the analog gamepad sticks.

    Since the mouse is always at a distance from the player (it determines the angle of the player) I pretty much always want the camera lerping to the player *and not "looking around"). I only want to "look" when the mouse is at the edge of the screen (like in an RTS game).

    The issue is, when the mouse goes to the edge of the screen and I start doing the "look"(and change the pointer to show it) there's an abrupt jump and vice versa when going away from the edge. Even if I change the lerp speed its still a little "vomity" for the player. It really has to be seamless because it can be triggered accidentally.

    So I think maybe there's a better way to do this? I've tried a few things but I'm a little stuck on coming up with a solution. Any suggestions? THANKS!

    dropbox.com/s/hatwal7zq4kiipd/LookCam_dop2000.c3p

    EDIT: it could be that I don't want to scroll back to the player after edging the screen. but then I run the risk of the "losing" the player not having them front and center. not really sure what to do. I don't know of any other games that do this. I play MOBAs that are similar, but their cameras are completely independent from the player so you can scroll around the entire map leaving your player completely off-screen (I don't want to do this).

  • after looking at this more, I think I can pinpoint where the camera starts to go wrong.

    if you are moving left and you scroll the mouse to the right edge and off again, it does the abrupt movement. I think it's because the mainCamera is trying to catch up to the player, then when the mouse goes to the edge, it jumps to the lookCam.

    it doesn't happen the other way (if you move left and look left) because the cam is behind the player or something along those lines... I can't quite figure it out! but I sort of understand it.

    I think I need to take into account the player's speed for the lerp value maybe?

    EDIT: oh its that clamp that is doing the really abrupt jump. but I think this is what I meant by needing an easing transition. its the maxdist that needs to be the max distance the player can be from the center of the screen (with regular cam). but when I set it to that value (around 200), then the camera is WAY too fast.

    EDIT2: so then I lowered the lookCam speed to 0.5 which helps a little. but still its wonky.

  • maybe this won't work. It can be pretty jarring (at times) no matter what I make the values. The problem is the main cam is lerping.

    the main reason for this functionality is giving the player the ability to see things that are slightly off screen, with a "look" function. Since my player is pretty much always moving, maybe its a given that the camera will be janky.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • so far the best setting is MainCam 1.0 and lookCam 0.25 MaxDist 200

    still it might make a player throw up, so without figuring a way to make this a smoother movement I don't know if this is a good idea!

  • Try simply setting the camera to halfway between the player and mouse position every tick.

    You can have the 'camera' object always on the mouse, and have both the camera and player object scroll to enabled.

  • oosyrag - I just tried it, not thinking that is quite right. but thanks for the suggestion.

    the idea is to have the camera "behaving normally" when the player is just dealing with the things relatively to the center of the screen. And to only do the extended camera when they need to see something on the edge of the screen. I only want that to happen in a deliberate sense (i.e the player is really trying to stay far away from some object, but they still want to see it).

    The problem happens when transitioning between these two modes since the main camera has a lerp on it.

  • Yeah I understood that was what you were going for, but it will probably be a bit jarring if you do that no matter how you implement it, and I haven't really seen any other game use a design like that. If you just always have the camera rotate and pan based on mouse position it will be much less dizzying I think.

  • I will test it a bit more, I'm not sure what the solution is...

    it definitely works better as a gamepad function. overloading the mouse with the direction and a "look" might just be too much

  • Probably the solution is to not use lerp. Instead move the scroll around by applying an acceleration which would eliminate the jarring. The idea is you’d want an ease in and out instead of the jarring ease out that typical uses of lerp provides.

    I don’t have the time today to make a complete example but the basic logic would be:

    Mouse is in edge region? Accelerate camera to a max distance

    Else decelerate back to 0.

    Anyways there’s more to it than that. The acceleration provides the smooth motion and you can utilize a formula so you can gradually stop at a specific location.

  • R0J0hound this makes sense and I love that idea, maybe I could put CustomMovement on the camera? although I feel like it could get unwieldly.

  • Tween might work. Will give it a go later.

  • CustomMovement is unwieldy, I never use it.

    Here's what I came up with:

    dropbox.com/s/jb23i3gx19ccktl/spring_camera.capx

    or radial instead

    dropbox.com/s/tt5p35r8r640mna/spring_camera_circle.capx

    Basically the camera is controlled by a damped spring which gives nice easing in and out. There are three variables you can tune:

    acceleration controls how fast it moves.

    stiffness controls how far you can look and how fast it returns to the center.

    damping gets rid of bouncing. higher values also make everything more sluggish. too low and there will be overshoot.

    Edit:

    Here the spring is applied to the whole camera instead of just the look around:

    dropbox.com/s/1lfz90zxj92bd9i/spring_camera_whole_camera.capx

    Kind of gives the impression of a real camera operator.

    Edit2:

    dropbox.com/s/42gs4g1tljsp35n/spring_camera_whole_camera2.capx

    Fix to ease down when scrolling to the edge of the layout.

  • R0J0hound wow, I really like the whole camera version! I notice you use LayoutHeight and Width, I don't totally understand that... does it have something to do with going to the edge of the layout? I noticed you used the hardcoded numbers for the viewport mid points: 320 & 240 (I think that is what you are saying at the end of your last post?)

    also, there is no "range" or maxdist from the center, so is it just the acceleration number I use to control how far the look goes? (playing around with it now)

  • R0J0hound this is really nice...beautiful movement effect! like you said its like a cinematic camera.

    doesn't seem to be accel that changes camera "look" dist from the player. I assume accel is just how "snappy" the cam is?

    the stiffness variable I assume is the easing when changing directions?

    and damping variable also for easing?

    d var is for how far the mouse goes before applying accel? but if the mouse is close what happens?

  • I was using screen shake (I used the Shake action from ScrollTo behav), so I wonder if I can seamlessly transition to that for the screen shake. I've made my own manual screen shake in the past but was never crazy about it - it just feels nice to have it in a behavior action.

    I'm surprised there are not more camera behavior options (like this spring cam) for ScrollTo. Right now ScrollTo behavior is so bare bones!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)