Need to tether a camera to the player and control it with the Right Analog Stick

0 favourites
  • 8 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Whats the best way to go about this?

    I tried 8-dir movement on the camera, but it's not working great.

    I'm trying to

    -make camera follow player when the right-stick is idle

    -move the camera independent of the player with the right stick

    -only let the camera move so far from the player

    -tether the camera to the player so the player even when the camera is fully extended so it can never move out of range of the player.

    any help would be appreciated!


  • I made some changes, have a look:

    EDIT - Actually, this version may be better:

  • dop2000 that is great! (only looked at the second one)

    so you are getting the angle and the extreme of the analog stick...dividing by the MaxDist and making that your clamp?

    one issue I had my original as well is if the analog stick is extended in place and simultaneously the player travels in the opposite direction...the result is that the player goes off screen. On the flip side, when the player moves towards the direction of the analog stick, the player proceeds the camera.

    to clamp the camera while the player is moving I've tried a few things. But I think it may have more to do with the lerp maybe?

    I added this to the Set Position:

    clamp(lerp(Self.X, (Player.X+d*cos(a)) , 2*dt), Self.X-100, Self.X+100)
    clamp(lerp(Self.y, (Player.y+d*sin(a)) , 2*dt), Self.Y-100,Self.Y+100)

    I made the lerp a little faster and so it won't go beyond 100 pixels in every direction, but that doesn't seem to be working either...

  • I don't quite understand what are you trying to do with those clamp() expressions, but they won't work like that.

    If you don't want the camera to go further than 100 px from the player, set MaxDist to 100. Also, try to increase camera speed in event 3 - change to "10*dt" for example.

  • dop2000 I tried setting MaxDist, it doesn't work for when the player is moving. It works for setting the max when the player is NOT moving. This is why I was saying I think it is the lerp(). When the player moves, the camera lerp is trying to catch up to where the player is, and that is adding to the distance away it is from the player.

    I'm talking about setting an overall clamp... i.e. never letting the camera go past 300 pixels to the right.

    EDIT I think I may have it. I set the MaxDist to 200 and the lerp to 5*dt and that seems to have done the trick. I see now why my clamp() wouldn't work.. :( that was dumb of me! it's early morning here!!

  • dop2000 thanks for the help!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can try this clamp:

    clamp(lerp(Self.X, (Player.X+d*cos(a)) , 5*dt), Player.X-MaxDist, Player.X+MaxDist)

    clamp(lerp(Self.y, (Player.y+d*sin(a)) , 5*dt), Player.Y-MaxDist, Player.Y+MaxDist)

  • dop2000 yeah that was the clamp I was trying to do... I got confused thinking the camera was the player which is why I did Self.X - I meant Player.X

    THANKS! very much appreciated!

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