How do I make a cross-hair "waggle" ?

Get help using Construct 2

Post » Wed Oct 29, 2014 4:18 pm

Hi,

maybe somebody can point me in the wright direction here..
i want to make a crosshair not exactly accurate to mouse position, like the shooter is breathing for example and the crosshair drifts somehow up/down left/right but a little bit unpredictable and smooth and i cant get it to work how i imagine it.
I tryed with two sine behaviours (horizontal/vertical) but the movement is somehow a combination of the two and doesnt feel right nor looks right.
I tryed with events that manipulate position but it turned out stuttering so i tryed using lerp and it got better but increased cpu usage too much and i couldnt figure out how to make it smooth without using 'every tick' and on top of that i couldnt make it much unpredictable.
Does someone have a better idea ?

best regards
Flo
B
38
S
11
G
5
Posts: 485
Reputation: 5,340

Post » Wed Oct 29, 2014 4:37 pm

I guess one way to do it would be to make two variables
MouseYdeviation
MouseXdeviation

Every tick set mouseYdeviation : MouseYdeviation+choose(-3,-2,-1,1,2,3)
Every tick set mouseXdeviation : MouseXdeviation+choose(-3,-2,-1,1,2,3)

And set the crosshair to mouse.x+MouseXdeviation , mouse.y+MouseYdeviation

Maybe using clamp to prevent it from deviating too much..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Oct 29, 2014 4:58 pm

@fldr I used the water effect on some text that I wanted to float around a little bit and it does something similar to what you are wanting. Try putting that effect on your sprite and adjusting the settings.
B
13
S
5
G
1
Posts: 119
Reputation: 2,292

Post » Wed Oct 29, 2014 5:22 pm

LittleStain wrote:I guess one way to do it would be to make two variables
MouseYdeviation
MouseXdeviation

Every tick set mouseYdeviation : MouseYdeviation+choose(-3,-2,-1,1,2,3)
Every tick set mouseXdeviation : MouseXdeviation+choose(-3,-2,-1,1,2,3)

And set the crosshair to mouse.x+MouseXdeviation , mouse.y+MouseYdeviation

Maybe using clamp to prevent it from deviating too much..

Improvisation from this, if you use lerp, you'll get realistic unsteady hold of a rifle/gun.

Code: Select all
[condition: Every tick]
[action: set crosshair position to lerp(mouse.x, mouse.x+choose(-3,-2,-1,1,2,3), steadinessParameter)]
[action: set crosshair position to lerp(mouse.y, mouse.y+choose(-3,-2,-1,1,2,3), steadinessParameter)]

variable steadinessParameter = 0.75 <--- responsive  but unsteady control
variable steadinessParameter = 0.25 <--- unresponsive but steadier control

The idea is the bigger the number (0<steadinessParameter<1) the better the feel of controlling the rifle. Using carp and cubic will give the desired effect but different movement pattern.
B
28
S
8
G
4
Posts: 553
Reputation: 4,924

Post » Wed Oct 29, 2014 6:47 pm

oh thank you all! will try this methods! thanks! :)
B
38
S
11
G
5
Posts: 485
Reputation: 5,340

Post » Wed Oct 29, 2014 9:32 pm

ok, so i tryed the watereffect, but its only visual distortion of the crosshair image, could it be that i did understand you wrong @roberjs3 ?

then i tryed your solutions @LittleStain and @DuckfaceNinja but its the same problem which i had with my trys, it moves aroudn way to fast, like its stuttering (see also attached capx, maybe you guys meant it otherwise then i implemented it [mousewheel to change parameter for duckfaceninja's solution])

http://fldr.de/crosshair
You do not have the required permissions to view the files attached to this post.
B
38
S
11
G
5
Posts: 485
Reputation: 5,340

Post » Wed Oct 29, 2014 10:23 pm

Try to start from here...
You do not have the required permissions to view the files attached to this post.
B
66
S
24
G
7
Posts: 1,514
Reputation: 11,039

Post » Wed Oct 29, 2014 10:45 pm

wow, very smooth! thank you!
do you have an idea why, when mouse isnt moved, it only lerps the y position?
B
38
S
11
G
5
Posts: 485
Reputation: 5,340

Post » Wed Oct 29, 2014 10:54 pm

it's not lerp......Vertical sine behavior :D


Try to add and horisontal whit same period...
B
66
S
24
G
7
Posts: 1,514
Reputation: 11,039

Post » Wed Oct 29, 2014 10:59 pm

oh yeah, its late here, totally overlooked that!
B
38
S
11
G
5
Posts: 485
Reputation: 5,340

Next

Return to How do I....?

Who is online

Users browsing this forum: ditocruz, dop2000, mcscooter and 22 guests