How do I set CameraSprite between player & mouse position

0 favourites
  • 7 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • How do I set my Camera Sprite between Player Sprite and Mouse Position?

    in a similar fashion to how nuclear throne does it - most likely using minimum &max values to stop the camera moving any further.

  • Just set your camera's position to the average position between your player and the mouse. Something like:

    X = (Player.X + Mouse.X) / 2

    Y = (Player.Y + Mouse.Y) / 2

    If you want to get fancy and control where in between the two your camera lies, you can use lerp:

    X = lerp(Player.X, Mouse.X, 0.25)

    Y = lerp(Player.Y, Mouse.Y, 0.25)

    This specific example would place the camera 25 percent of the way from the player to the mouse.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • thanks linkman2004 luckily I was able to resolve my little problem. This was the end result I got and was going for.

    I did it by doing this. made it changeable for any later uses . no performance hit after few seconds after start of the layout -

    used windows snipping tool on windows 8.1 to get the custom screenshot

  • I wouldn't recommend using dt in a lerp function like that, as it's likely not doing what you think it is. If your FPS -- and by association, the value of dt -- starts to fluctuate, you'll find your camera jumping around. If you want smooth camera movement with dt, you should be lerping the camera position toward a fixed point between the player and mouse.

    Alternatively, you could look at my Magicam plugin, which does motion smoothing and multi-object following.

  • linkman2004 Understood. I'm quite use to using it in other engines with games running at frame rate ranging from 30 -1000+ FPS. made the lerp speed more quickly understood by any group members.

    trying to not use any third party plugins as much as I can but thanks.

  • Set up a Camera Sprite and Say Every tick camera set position lerp(Mouse.x, Player.x, 0.3) if that doesn't work then swap the player and mouse because one of the orders doesn't work. Hope this helps :/

  • still can't believe i asked this 5yrs ago! time flies!

    damn this brings back memories, i figured out a solution which was just offsetting the camera from the player's position and scaling a set distance based on how far their cursor is on the screen + got it to also do the game with a controller except the first part wasn't needed.

    and this is the code i made to get it to work based on whatever distance it could be given.

    ended up looking like this. this is from a project template I made for my patrons at (patreon.com/SalmanShh)

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