How do I Make the Crosshair slowly follow player

Get help using Construct 2

Post » Mon Apr 11, 2016 2:11 am

Image

Hey guys i am trying to figure out how to make the crosshair slowly follow the player. I know if setting position to another object it would directly go to the player instantly and that's not what i want. Any assistance would be greatly appreciated.
Image
B
60
S
32
G
5
Posts: 118
Reputation: 8,325

Post » Mon Apr 11, 2016 2:37 am

Put pathfinding on the crosshair, and set the the speed to what you consider slow. Then you must make an event to find a path towards the player every tick, and make an event where once a path to the player has been found, it will move along that path. This way it will constantly follow the player in a natural way, and you can even give it obstacles it has to go around it you like.
B
28
S
11
G
4
Posts: 77
Reputation: 4,321

Post » Mon Apr 11, 2016 3:24 am

I'm assuming your crosshair is just on top of the screen and likely wouldn't need to go around things (why would it?). You need to set its position over time. I'd, personally, use lerp for this.

If --compare two values-- Distance(player.X,player.Y,crosshair.X,crosshair.Y) > 5,
Then crosshair>set position> X: lerp(Self.X, player.X, 3*dt), Y: lerp(Self.Y, player.Y, 3*dt)

Change the "3" to change the speed of the effect. The "5" up there is a small deadzone at your player's origin--technically not necessary.

This manual entry will explain those system expressions a little more if you need it. The gist (for these purposes) is it will slowly move towards the player and decelerate as it arrives (side note: technically, it will never arrive, but you can just round it off when its close enough). You could use fancier ways to get it to move, but this is a simple way to give a constant, smooth motion towards a target.
B
103
S
38
G
19
Posts: 962
Reputation: 17,996

Post » Tue Apr 12, 2016 1:49 am

@C-7 @PrimalNews got it working thank you very much! :D
Image
B
60
S
32
G
5
Posts: 118
Reputation: 8,325


Return to How do I....?

Who is online

Users browsing this forum: gskunk, tarek2 and 38 guests