# CameraShakeSettings

Kind: Class · Namespace: Sansar.Simulation · Assembly: Sansar.Simulation.dll · Script API 47.10.0

<div class="api-meta">
<span class="api-kind api-kind-class" data-pagefind-filter="kind:Class">Class</span>
<span data-pagefind-filter="namespace:Sansar.Simulation">Namespace <a href="/scripting/api/sansar.simulation"><code>Sansar.Simulation</code></a></span>
<span class="api-badge api-new">New in 47.10.0</span>
</div>

<span id="T:Sansar.Simulation.CameraShakeSettings"></span>

Configures a camera shake; changes affect subsequent starts only.

```csharp
public sealed class CameraShakeSettings
```

## Remarks

Starts snapshot these settings and apply the documented bounds. Player comfort settings and VR limits can reduce or suppress any shake. A shake ends when the player leaves the world.

```csharp title="CameraShakeExample.cs"
/* This example is licensed under the Creative Commons Attribution 4.0 International License.
 * Copyright 2026 Sansar, Inc. https://creativecommons.org/licenses/by/4.0/
 */

using System;
using System.Collections.Generic;
using Sansar;
using Sansar.Script;
using Sansar.Simulation;

/// <summary>Demonstrates camera shake with chat commands on the default channel.</summary>
/// <remarks>Use /shake rumble, jitter, sway, impact, near, engine or stop.
/// Engine toggles a continuous rumble for the sender; stop clears this script's shakes for everyone.
/// An optional CameraComponent on this object fixes the view for current and future users.
/// Player comfort settings and VR limits can reduce or suppress the motion.</remarks>
public class CameraShakeExample : SceneObjectScript
{
    private CameraComponent camera;
    private readonly Dictionary<SessionId, CameraShakeHandle> engines =
        new Dictionary<SessionId, CameraShakeHandle>();

    /// <summary>Sets up chat commands and the optional fixed camera.</summary>
    public override void Init()
    {
        ObjectPrivate.TryGetFirstComponent(out camera);
        ScenePrivate.User.Subscribe(User.AddUser, OnUserAdded);
        ScenePrivate.User.Subscribe(User.RemoveUser, OnUserRemoved);
        ScenePrivate.Chat.Subscribe(Chat.DefaultChannel, OnChat, true);

        // Script reloads also need to set up users who are already in the world.
        foreach (AgentPrivate agent in ScenePrivate.GetAgents())
        {
            SetCamera(agent);
        }

        // The Debug local-source live test requires this marker from the real body.
        Log.Write("CameraShakeExample ready (real shake body): /shake rumble, jitter, sway, impact, near, engine, stop");
    }

    private void SetCamera(AgentPrivate agent)
    {
        if (camera != null && agent != null && agent.IsValid)
        {
            agent.Client.SetActiveCamera(camera, ScriptCameraControlMode.AgentControlOnly);
        }
    }

    private void OnUserAdded(UserData data)
    {
        SetCamera(ScenePrivate.FindAgent(data.User));
    }

    private void OnUserRemoved(UserData data)
    {
        // Leaving the world ends that player's shake; discard the old session's handle.
        engines.Remove(data.User);
    }

    private bool StopEngine(SessionId sessionId)
    {
        CameraShakeHandle engine;
        if (!engines.TryGetValue(sessionId, out engine))
        {
            return false;
        }

        engine.Stop(0.25f);
        engines.Remove(sessionId);
        return true;
    }

    private void OnChat(ChatData data)
    {
        string[] words = data.Message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (words.Length != 2 || !words[0].Equals("/shake", StringComparison.OrdinalIgnoreCase))
        {
            return;
        }

        // SourceId identifies the sender, rather than the object running this script.
        AgentPrivate agent = ScenePrivate.FindAgent(data.SourceId);
        if (agent == null || !agent.IsValid)
        {
            return;
        }
        SessionId sessionId = agent.AgentInfo.SessionId;

        switch (words[1].ToLowerInvariant())
        {
            case "rumble":
                // Presets are mutable: edit before starting. Starts snapshot the settings.
                CameraShakeSettings rumble = CameraShakeSettings.Earthquake();
                rumble.Direction = new Vector(1, 0.5f, 0);
                agent.Client.ShakeCamera(rumble);
                break;

            case "jitter":
                agent.Client.ShakeCamera(new CameraShakeSettings
                {
                    Pattern = CameraShakePattern.Jitter,
                    Magnitude = 0.25f,
                    Duration = 1.0f
                    // Frequency 0 uses Jitter's default of 20 Hz.
                });
                break;

            case "sway":
                // Long side-to-side motion for the fixed-camera pixel-displacement test.
                agent.Client.ShakeCamera(new CameraShakeSettings
                {
                    Pattern = CameraShakePattern.Sway,
                    Magnitude = 0.6f,
                    Frequency = 2.0f,
                    Duration = 6.0f,
                    Direction = new Vector(1, 0, 0),
                    FadeOut = 0.3f
                });
                break;

            case "impact":
                // Landing: one downward kick. Duration 0 would still give just one kick.
                agent.Client.ShakeCamera(CameraShakeSettings.Impact(new Vector(0, -1, 0)));
                break;

            case "near":
                // Only players present now receive this explosion. Their camera distance
                // from this object's world position controls falloff to zero at 20 meters.
                ScenePrivate.ShakeCameraAtPosition(ObjectPrivate.Position, 20.0f,
                    CameraShakeSettings.Explosion());
                break;

            case "engine":
                // Send again to stop; separate sessions retain separate handles.
                if (!StopEngine(sessionId))
                {
                    engines[sessionId] = agent.Client.ShakeCamera(CameraShakeSettings.EngineRumble());
                }
                break;

            case "stop":
                StopEngine(sessionId);
                // Both stop-all scopes affect only shakes requested by this script.
                agent.Client.StopAllCameraShakes();
                ScenePrivate.StopAllCameraShakes();
                engines.Clear();
                break;
        }
    }
}
```

<p class="api-example-source">Source: <code>Examples/CameraShakeExample.cs</code> in the Sansar 47.10.0 client ScriptApi snapshot.</p>

## Members at a glance

| Kind | Members |
|---|---|
| **Constructors** | [CameraShakeSettings](#camerashakesettings)&#160;<span class="api-dot" title="New in 47.10.0"><span class="api-sr">New in 47.10.0</span></span> |
| **Properties** | [Direction](#direction)&#160;<span class="api-dot" title="New in 47.10.0"><span class="api-sr">New in 47.10.0</span></span> · [Duration](#duration)&#160;<span class="api-dot" title="New in 47.10.0"><span class="api-sr">New in 47.10.0</span></span> · [FadeOut](#fadeout)&#160;<span class="api-dot" title="New in 47.10.0"><span class="api-sr">New in 47.10.0</span></span> · [Frequency](#frequency)&#160;<span class="api-dot" title="New in 47.10.0"><span class="api-sr">New in 47.10.0</span></span> · [Magnitude](#magnitude)&#160;<span class="api-dot" title="New in 47.10.0"><span class="api-sr">New in 47.10.0</span></span> · [Pattern](#pattern)&#160;<span class="api-dot" title="New in 47.10.0"><span class="api-sr">New in 47.10.0</span></span> |
| **Methods** | [Earthquake](#earthquake)&#160;<span class="api-dot" title="New in 47.10.0"><span class="api-sr">New in 47.10.0</span></span> · [EngineRumble](#enginerumble)&#160;<span class="api-dot" title="New in 47.10.0"><span class="api-sr">New in 47.10.0</span></span> · [Explosion](#explosion)&#160;<span class="api-dot" title="New in 47.10.0"><span class="api-sr">New in 47.10.0</span></span> · [Impact](#impact)&#160;<span class="api-dot" title="New in 47.10.0"><span class="api-sr">New in 47.10.0</span></span> |

## Constructors

### CameraShakeSettings

<div class="api-card">
<span id="M:Sansar.Simulation.CameraShakeSettings.#ctor"></span>
<span id="C:Sansar.Simulation.CameraShakeSettings()"></span>
<div class="api-badges"><span class="api-badge api-new">New in 47.10.0</span></div>

```csharp signature
public CameraShakeSettings()
```

Creates a one-second rumble with moderate magnitude.

<details class="api-remarks"><summary>Remarks</summary>

Frequency 0 selects 6 Hz; magnitude is 0.35, direction is (1,1,1) and fade-out is 0.15 seconds.

</details>

</div>


## Properties

### Direction

<div class="api-card">
<span id="P:Sansar.Simulation.CameraShakeSettings.Direction"></span>
<div class="api-badges"><span class="api-badge api-new">New in 47.10.0</span></div>

```csharp signature
public Sansar.Vector Direction { get; set; }
```

Gets or sets camera-space right/up/forward weights; the default is (1,1,1).

<details class="api-remarks"><summary>Remarks</summary>

X is right, Y is up and Z is forward; W is ignored. Weights are clamped to \[-1,1\] and vectors longer than 1 are normalized. Zero gives no motion. Signs select the first kick or half-cycle for Impact or Sway.

</details>

</div>

### Duration

<div class="api-card">
<span id="P:Sansar.Simulation.CameraShakeSettings.Duration"></span>
<div class="api-badges"><span class="api-badge api-new">New in 47.10.0</span></div>

```csharp signature
public float Duration { get; set; }
```

Gets or sets duration in seconds; 0 means until stopped.

<details class="api-remarks"><summary>Remarks</summary>

The default is 1 second. Values are clamped to 0 through 600; positive values below 0.05 become 0.05. Retain the handle for continuous effects. Impact with Duration 0 is still one decaying kick.

</details>

</div>

### FadeOut

<div class="api-card">
<span id="P:Sansar.Simulation.CameraShakeSettings.FadeOut"></span>
<div class="api-badges"><span class="api-badge api-new">New in 47.10.0</span></div>

```csharp signature
public float FadeOut { get; set; }
```

Gets or sets the ending fade in seconds; the default is 0.15.

<details class="api-remarks"><summary>Remarks</summary>

Clamped to 0 through 5 seconds and shortened to fit Duration. The fade is included in Duration. For Duration 0, Stop specifies the fade.

</details>

</div>

### Frequency

<div class="api-card">
<span id="P:Sansar.Simulation.CameraShakeSettings.Frequency"></span>
<div class="api-badges"><span class="api-badge api-new">New in 47.10.0</span></div>

```csharp signature
public float Frequency { get; set; }
```

Gets or sets frequency in Hz; 0 selects the pattern default.

<details class="api-remarks"><summary>Remarks</summary>

Defaults are 6 Hz for Rumble, 20 for Jitter, 1.5 for Sway and 5 for Impact. Other values are clamped to 0.1 through 30 Hz.

</details>

</div>

### Magnitude

<div class="api-card">
<span id="P:Sansar.Simulation.CameraShakeSettings.Magnitude"></span>
<div class="api-badges"><span class="api-badge api-new">New in 47.10.0</span></div>

```csharp signature
public float Magnitude { get; set; }
```

Gets or sets relative strength from 0 to 1; the default is 0.35.

<details class="api-remarks"><summary>Remarks</summary>

Values are clamped to this range. This is a relative amount, not a physical impulse.

</details>

</div>

### Pattern

<div class="api-card">
<span id="P:Sansar.Simulation.CameraShakeSettings.Pattern"></span>
<div class="api-badges"><span class="api-badge api-new">New in 47.10.0</span></div>

```csharp signature
public CameraShakePattern Pattern { get; set; }
```

Gets or sets the motion pattern; the default is Rumble.

<details class="api-remarks"><summary>Remarks</summary>

Choose Rumble, Jitter, Sway or Impact.

</details>

</div>


## Methods

### Earthquake

<div class="api-card">
<span id="M:Sansar.Simulation.CameraShakeSettings.Earthquake(System.Single,System.Single)"></span>
<div class="api-badges"><span class="api-badge api-new">New in 47.10.0</span></div>

```csharp signature
public static CameraShakeSettings Earthquake(
    float magnitude,
    float duration
)
```

Creates a slow rumble suitable for an earthquake.

| Parameter | Type | Description |
|---|---|---|
| `magnitude` | [float](https://learn.microsoft.com/dotnet/api/system.single) | Relative strength from 0 to 1; defaults to 0.35. |
| `duration` | [float](https://learn.microsoft.com/dotnet/api/system.single) | Duration in seconds; defaults to 5. Use 0 for until stopped. |

**Returns:** [CameraShakeSettings](/scripting/api/sansar.simulation/camerashakesettings) — A fresh, mutable settings object.

<details class="api-remarks"><summary>Remarks</summary>

Uses 3 Hz and fade-out 0.8 seconds. Edit settings before starting.

</details>

</div>

### EngineRumble

<div class="api-card">
<span id="M:Sansar.Simulation.CameraShakeSettings.EngineRumble(System.Single)"></span>
<div class="api-badges"><span class="api-badge api-new">New in 47.10.0</span></div>

```csharp signature
public static CameraShakeSettings EngineRumble(float magnitude)
```

Creates a subtle continuous rumble; retain its handle to stop it.

| Parameter | Type | Description |
|---|---|---|
| `magnitude` | [float](https://learn.microsoft.com/dotnet/api/system.single) | Relative strength from 0 to 1; defaults to 0.12. |

**Returns:** [CameraShakeSettings](/scripting/api/sansar.simulation/camerashakesettings) — A fresh, mutable settings object.

<details class="api-remarks"><summary>Remarks</summary>

Uses 16 Hz and Duration 0, until stopped. Edit settings before starting.

</details>

</div>

### Explosion

<div class="api-card">
<span id="M:Sansar.Simulation.CameraShakeSettings.Explosion(System.Single)"></span>
<div class="api-badges"><span class="api-badge api-new">New in 47.10.0</span></div>

```csharp signature
public static CameraShakeSettings Explosion(float magnitude)
```

Creates a short, strong rumble suitable for an explosion.

| Parameter | Type | Description |
|---|---|---|
| `magnitude` | [float](https://learn.microsoft.com/dotnet/api/system.single) | Relative strength from 0 to 1; defaults to 0.7. |

**Returns:** [CameraShakeSettings](/scripting/api/sansar.simulation/camerashakesettings) — A fresh, mutable settings object.

<details class="api-remarks"><summary>Remarks</summary>

Uses 12 Hz, duration 0.65 seconds and fade-out 0.55 seconds. Edit settings before starting.

</details>

</div>

### Impact

<div class="api-card">
<span id="M:Sansar.Simulation.CameraShakeSettings.Impact(Sansar.Vector,System.Single)"></span>
<div class="api-badges"><span class="api-badge api-new">New in 47.10.0</span></div>

```csharp signature
public static CameraShakeSettings Impact(
    Sansar.Vector direction,
    float magnitude
)
```

Creates one kick in the given camera-space right/up/forward direction.

| Parameter | Type | Description |
|---|---|---|
| `direction` | [Sansar.Vector](/scripting/api/sansar/vector) | Camera-space right/up/forward weights; W is ignored. |
| `magnitude` | [float](https://learn.microsoft.com/dotnet/api/system.single) | Relative strength from 0 to 1; defaults to 0.5. |

**Returns:** [CameraShakeSettings](/scripting/api/sansar.simulation/camerashakesettings) — A fresh, mutable settings object.

<details class="api-remarks"><summary>Remarks</summary>

Uses 5 Hz and duration 0.45 seconds. Changing Duration to 0 still gives only one decaying kick.

</details>

</div>


## Used in examples

- `CameraShakeExample.cs`

<p class="api-generated" data-pagefind-ignore>Generated from the Sansar 47.10.0 client ScriptApi snapshot.</p>