# SCharacterController

**الأعضاء** 15

|       |                                                 |                                                                                                                                           |
| ----- | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| دالة  | [ClosestPointOnBounds](#closestpointonbounds)   | The closest point to the bounding box of the attached collider.                                                                           |
| دالة  | [ClosestPoint](#closestpoint)                   | The point on the collider that is closest to the specified location.                                                                      |
| دالة  | [SimpleMove](#simplemove)                       | Moves the character with speed.                                                                                                           |
| دالة  | [Move](#move)                                   | Supplies the movement of a SGameObject with an attached SCharacterController component.                                                   |
| خاصية | [Center](#center)                               | Returns Center Vector value of the Character Controller.                                                                                  |
| خاصية | [DetectCollisions](#detectcollisions)           | Determines whether other rigidbodies or character controllers collide with this character controller (by default this is always enabled). |
| خاصية | [EnableOverlapRecovery](#enableoverlaprecovery) | Enables or disables overlap recovery.                                                                                                     |
| خاصية | [Height](#height)                               | The height of the character's capsule.                                                                                                    |
| خاصية | [MinMoveDistance](#minmovedistance)             | Gets or sets the minimum move distance of the character controller.                                                                       |
| خاصية | [Radius](#radius)                               | The radius of the character's capsule.                                                                                                    |
| خاصية | [SkinWidth](#skinwidth)                         | The character's collision skin width.                                                                                                     |
| خاصية | [SlopeLimit](#slopelimit)                       | The character controllers slope limit in degrees.                                                                                         |
| خاصية | [StepOffset](#stepoffset)                       | The character controllers step offset in meters.                                                                                          |
| خاصية | [Velocity](#velocity)                           | The current relative velocity of the Character.                                                                                           |
| خاصية | [GameObject](#gameobject)                       | Returns a reference to the GameObject of this component.                                                                                  |

## الدوال

### ClosestPointOnBounds

[SVector](/docs/ar/scripting/client-scripting-api-reference/types/svector.md) ClosestPointOnBounds([SVector](/docs/ar/scripting/client-scripting-api-reference/types/svector.md) position)

The closest point to the bounding box of the attached collider. This can be used to calculate hit points when applying explosion damage.

المعاملات

| الاسم    | النوع                                                                         | القيمة الافتراضية |
| -------- | ----------------------------------------------------------------------------- | ----------------- |
| position | [SVector](/docs/ar/scripting/client-scripting-api-reference/types/svector.md) | –                 |

القيم المرجعة

`SVector`

مثال

**Lua**

```lua
closestPoint = Space.Host.ExecutingObject.CharacterController.ClosestPointOnBounds(Vector.New(0,0,0))

```

### ClosestPoint

[SVector](/docs/ar/scripting/client-scripting-api-reference/types/svector.md) ClosestPoint([SVector](/docs/ar/scripting/client-scripting-api-reference/types/svector.md) position)

The point on the collider that is closest to the specified location.

المعاملات

| الاسم    | النوع                                                                         | القيمة الافتراضية |
| -------- | ----------------------------------------------------------------------------- | ----------------- |
| position | [SVector](/docs/ar/scripting/client-scripting-api-reference/types/svector.md) | –                 |

القيم المرجعة

`SVector`

مثال

**Lua**

```lua
closestPoint = Space.Host.ExecutingObject.CharacterController.ClosestPoint = Vector.New(0,0,0)

```

### SimpleMove

bool SimpleMove([SVector](/docs/ar/scripting/client-scripting-api-reference/types/svector.md) speed)

Moves the character with speed. Velocity along the y-axis is ignored. Speed is in units/s. Gravity is automatically applied.

Returns if the character is grounded.

It is recommended that you make only one call to Move or SimpleMove per frame.

المعاملات

| الاسم | النوع                                                                         | القيمة الافتراضية |
| ----- | ----------------------------------------------------------------------------- | ----------------- |
| speed | [SVector](/docs/ar/scripting/client-scripting-api-reference/types/svector.md) | –                 |

القيم المرجعة

`bool`

مثال

**Lua**

```lua
isGrounded = Space.Host.ExecutingObject.CharacterController.SimpleMove = Vector.New(100,0,0)

```

### Move

int Move([SVector](/docs/ar/scripting/client-scripting-api-reference/types/svector.md) motion)

Supplies the movement of a [*SGameObject*](/docs/ar/scripting/client-scripting-api-reference/types/sgameobject.md) with an attached SCharacterController component.

The SCharacterController.Move motion moves the [*SGameObject*](/docs/ar/scripting/client-scripting-api-reference/types/sgameobject.md) in the given direction. The given direction requires absolute movement delta values. A collision constrains the Move from taking place.

Returns an int indicating the direction of a collision: None (0), Sides (1), Above (2), and Below (3). SCharacterController.Move does not use gravity.

المعاملات

| الاسم  | النوع                                                                         | القيمة الافتراضية |
| ------ | ----------------------------------------------------------------------------- | ----------------- |
| motion | [SVector](/docs/ar/scripting/client-scripting-api-reference/types/svector.md) | –                 |

القيم المرجعة

`int`

مثال

**Lua**

```lua
collisionDirection = Space.Host.ExecutingObject.CharacterController.Move = Vector.New(100,0,0)

```

## الخصائص

### Center

[SVector](/docs/ar/scripting/client-scripting-api-reference/types/svector.md) Center {get; set; }

Returns Center Vector value of the Character Controller.

مثال

**Lua**

```lua
Space.Host.ExecutingObject.CharacterController.Center = Vector.New(0,0,0) 

```

### DetectCollisions

bool DetectCollisions {get; set; }

Determines whether other rigidbodies or character controllers collide with this character controller (by default this is always enabled).

This method does not affect collisions detected during the character controller's movement but rather decides whether an incoming collider will be blocked by the controller's collider. For example, a box collider in the Scene will block the movement of the controller, but the box may still fall through the controller if detectCollisions is false. This property is useful to disable the character controller temporarily. For example, you might want to mount a character into a car and disable collision detection until it exits the car again.

مثال

**Lua**

```lua
Space.Host.CharacterController.DetectCollisions= false

```

**Lua**

```lua
--clicking this object will toggle a Character Controller's Detect Collisions property

thisObject = Space.Host.ExecutingObject
ccontroller = Space.Host.GetReference("thecharactercontroller").CharacterController --add Reference to Scripting Runtime


function OnClickFunction()
ccontroller.DetectCollisions = not ccontroller.DetectCollisions
end

thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)

```

### EnableOverlapRecovery

bool EnableOverlapRecovery {get; set; }

Enables or disables overlap recovery. Enables or disables overlap recovery. Used to depenetrate character controllers from static objects when an overlap is detected.

Overlap recovery can be used to depenetrate character controllers (CCTs) from static objects when an overlap is detected. This can happen in three main cases:

\- when the CCT is directly spawned or teleported in another object

\- when the CCT algorithm fails due to limited FPU accuracy

\- when the "up vector" is modified, making the rotated CCT shape overlap surrounding objects

When activated, the CCT module will automatically try to resolve the penetration, and move the CCT to a safe place where it does

not overlap other objects anymore. This only concerns static objects, dynamic objects are ignored by overlap recovery.

When overlap recovery is not activated, it is possible for the CCTs to go through static objects. By default, overlap recovery is enabled.

Overlap recovery currently works with all geometries except heightfields.

مثال

**Lua**

```lua
Space.Host.CharacterController.EnableOverlapRecovery= false

```

**Lua**

```lua
--clicking this object will toggle a Character Controller's Enable Overlap Recovery property

thisObject = Space.Host.ExecutingObject
ccontroller = Space.Host.GetReference("thecharactercontroller").CharacterController --add Reference to Scripting Runtime


function OnClickFunction()
ccontroller.EnableOverlapRecovery = not ccontroller.EnableOverlapRecovery
end

thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)

```

### Height

float Height {get; set; }

The height of the character's capsule.

مثال

**Lua**

```lua
Space.Host.ExecutingObject.CharacterController.Height = 4

```

**Lua**

```lua
--the below script will make a slider change a Character Controller Height property
--[Add "theslider" and "thecharactercontroller" to the Object References section in Scripting Runtime component]

slider = Space.Host.GetReference("theslider").UISlider 
ccontroller = Space.Host.GetReference("thecharactercontroller").CharacterController 


OVC = function()
ccontroller.Height = (slider.Value * 10.0) -- from 0.0 to 10.0
end

slider.OnValueChanged(OVC)

```

### MinMoveDistance

float MinMoveDistance {get; set; }

Gets or sets the minimum move distance of the character controller.

مثال

**Lua**

```lua
Space.Host.ExecutingObject.CharacterController.MinMoveDistance = 3

```

**Lua**

```lua
--this script will make a slider change a Character Controller Min Move Distance property
--[Add "theslider" and "thecharactercontroller" to the Object References section in Scripting Runtime component]

slider = Space.Host.GetReference("theslider").UISlider 
ccontroller = Space.Host.GetReference("thecharactercontroller").CharacterController 


OVC = function()
ccontroller.MinMoveDistance= (slider.Value * 10.0) -- from 0.0 to 10.0
end

slider.OnValueChanged(OVC)

```

### Radius

float Radius {get; set; }

The radius of the character's capsule.

مثال

**Lua**

```lua
Space.Host.ExecutingObject.CharacterController.Radius = 5

```

**Lua**

```lua
--this script will make a slider change a Character Controller Radius property
--[Add "theslider" and "thecharactercontroller" to the Object References section in Scripting Runtime component]

slider = Space.Host.GetReference("theslider").UISlider 
ccontroller = Space.Host.GetReference("thecharactercontroller").CharacterController 


OVC = function()
ccontroller.Radius= (slider.Value * 10.0) -- from 0.0 to 10.0
end

slider.OnValueChanged(OVC)

```

### SkinWidth

float SkinWidth {get; set; }

The character's collision skin width.

مثال

**Lua**

```lua
Space.Host.ExecutingObject.CharacterController.SkinWidth = 4

```

**Lua**

```lua
--this script will make a slider change a Character Controller SkinWidth property
--[Add "theslider" and "thecharactercontroller" to the Object References section in Scripting Runtime component]

slider = Space.Host.GetReference("theslider").UISlider 
ccontroller = Space.Host.GetReference("thecharactercontroller").CharacterController 


OVC = function()
ccontroller.SkinWidth= (slider.Value * 10.0) -- from 0.0 to 10.0
end

slider.OnValueChanged(OVC)

```

### SlopeLimit

float SlopeLimit {get; set; }

The character controllers slope limit in degrees.

مثال

**Lua**

```lua
Space.Host.ExecutingObject.CharacterController.SlopeLimit= 2

```

**Lua**

```lua
--this script will make a slider change a Character Controller Slope Limit property
--[Add "theslider" and "thecharactercontroller" to the Object References section in Scripting Runtime component]

slider = Space.Host.GetReference("theslider").UISlider 
ccontroller = Space.Host.GetReference("thecharactercontroller").CharacterController 


OVC = function()
ccontroller.SlopeLimit= (slider.Value * 180.0) -- from 0.0 to 180.0
end

slider.OnValueChanged(OVC)

```

### StepOffset

float StepOffset {get; set; }

The character controllers step offset in meters.

مثال

**Lua**

```lua
Space.Host.ExecutingObject.CharacterController.StepOffset= 2

```

**Lua**

```lua
--this script will make a slider change a Character Controller Step Offset property
--[Add "theslider" and "thecharactercontroller" to the Object References section in Scripting Runtime component]

slider = Space.Host.GetReference("theslider").UISlider 
ccontroller = Space.Host.GetReference("thecharactercontroller").CharacterController 


OVC = function()
ccontroller.StepOffset= (slider.Value * 10.0) -- from 0.0 to 10.0
end

slider.OnValueChanged(OVC)

```

### Velocity

[SVector](/docs/ar/scripting/client-scripting-api-reference/types/svector.md) Velocity {get; }

The current relative velocity of the Character.

مثال

**Lua**

```lua
currentRelativeVelocity = Space.Host.ExecutingObject.CharacterController.Velocity

```

### GameObject

[SGameObject](/docs/ar/scripting/client-scripting-api-reference/types/sgameobject.md) GameObject {get; }

Returns a reference to the GameObject of this component.

مثال

**Lua**

```lua
theGameObject = Space.Host.ExecutingObject.CharacterController.GameObject

```
