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

0 favourites
  • 15 posts
  • 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

  • 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..

  • 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.

  • 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.

    [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[/code:334wjsa1]
    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.
  • oh thank you all! will try this methods! thanks!

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

    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

  • Try to start from here...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • wow, very smooth! thank you!

    do you have an idea why, when mouse isnt moved, it only lerps the y position?

  • it's not lerp......Vertical sine behavior

    Try to add and horisontal whit same period...

  • oh yeah, its late here, totally overlooked that!

  • Ergebnis...

  • What about

    Set X to lerp(Sprite.X, random(Mouse.X-XXX, Mouse.X+XXX), YYY)

    and same for Y

    XXX - is a distance how far from mouse position it can go

    YYY - how fast it should move

  • Every tick?

  • 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])

    You have to tweak them to get realistic movement. Kind of hard to explain, look at capx attached. You have to tweak the parameters to get the movement you satisfy with.

    [attachment=0:1bhu81ys][/attachment:1bhu81ys]

  • > 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])

    >

    You have to tweak them to get realistic movement. Kind of hard to explain, look at capx attached. You have to tweak the parameters to get the movement you satisfy with.

    [attachment=0:21f7p9jc][/attachment:21f7p9jc]

    yeah, now were talking

    thats what i had in mind! thank you very much!

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