How do I Follw the mouse slowly

0 favourites
  • 3 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • So I have a gun in my game and I want it to follow the mouse but not immediately. I was toying around with maybe making it a bullet behavior and make it follow the mouse but when the angle changes it spins and I don't want that. Any suggestions?

  • Try using the function Lerp(a,b,t).

    A and B are main values and T is a value between 0 and 1 that represents a position between A and B.

    So Lerp(0,10,0.5) will return 5.

    Knowing that you can set the position of the camera to be somewhere between the position of the camera itself and the position of the mouse.

    That way if the camera and mouse position are the same, Lerp() will return the current value, therefore setting the camera at the same place. If the player moves the mouse only a little, Lerp() will return really small values, making the camera move only a little and really smooth. And if the player moves the mouse faster and farther Lerp() will return bigger values moving the camera faster to where the mouse is.

    Note that the values of Lerp() will be always changing, so the camera will start moving faster if it's far from the mouse, but will decrease it's speed as it gets closer to the mouse, giving an really nice and smooth effect for your game.

    I use it all the time, you should try it.

    The code will be something like this:

    Every tick > Set Camera X to > Lerp(Camera.X , Mouse.X , 0.5)

    Set Camera Y to > Lerp(Camera.Y , Mouse.Y , 0.5)

    Note that you can change the last number to try and adjust the effect to be the way you want.

    A higher number will result in a faster camera movement, being 1 a instant transition, while lower numbers will result in a slower and smoother camera in a way that 0 won't move the camera at all.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you!

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