How do I Follw the mouse slowly

Get help using Construct 2

Post » Mon Jun 15, 2015 11:54 pm

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?
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Tue Jun 16, 2015 3:47 am

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.

;)
B
17
S
7
Posts: 277
Reputation: 2,514

Post » Tue Jun 16, 2015 1:17 pm

Thank you!
B
22
S
8
Posts: 203
Reputation: 2,059


Return to How do I....?

Who is online

Users browsing this forum: namaewayukidesu, Richterrii and 15 guests