0
\$\begingroup\$

I want to simulate that random and soft movement that lot of games got (like BF3) when you use the scope of a sniper gun, so the question is how to achieve that.

\$\endgroup\$
2
  • \$\begingroup\$ Do you need an algorithm how to calculate the involuntary movement or do you need a way to implement the movement itself? \$\endgroup\$
    – Philipp
    Aug 7, 2014 at 8:33
  • 1
    \$\begingroup\$ Just the algorithm \$\endgroup\$
    – zappp
    Aug 8, 2014 at 4:06

1 Answer 1

1
\$\begingroup\$

You could randomly take a new looking direction or a point to look at for the camera, then just lerp or smooth damp towards it. Here is a simple example made with Unity that might get you started, feel free to modify it. You might also want to add player's camera movement to that so the player can actually control aiming.

private float t;
private Vector2 randomPoint;
private Vector3 lookAtPoint;
private Vector3 lookFromPoint;
private const float RADIUS = 0.1f;
private const float MOVEMENT_TIME = 1.0f;

void Start () {
    t = MOVEMENT_TIME;
    lookFromPoint = transform.forward;
}

void Update () {
    if (t >= MOVEMENT_TIME) {
        randomPoint = Random.insideUnitCircle * RADIUS;
        lookFromPoint = lookAtPoint;
        lookAtPoint = new Vector3(transform.forward.x + randomPoint.x, transform.forward.y + randomPoint.y, transform.forward.z);
        t = 0.0f;
    }
    else {
        t += Time.deltaTime;
        transform.LookAt(Vector3.Slerp(lookFromPoint, lookAtPoint, t));
    }
}
\$\endgroup\$
1
  • \$\begingroup\$ I had already tried using a simple random but the result isn't that 'soft', I mean it doesn't look natural at all \$\endgroup\$
    – zappp
    Aug 8, 2014 at 4:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .