GetBodyTransform.cs
using Sandbox;
public sealed class GetBodyTransform : Component
{
[Property] public float xForce { get; set; } = 15.0f;
[Property] public float zForce { get; set; } = 15.0f;
[Property] public float yForce { get; set; } = 20000.0f;
protected override void OnUpdate()
{
// this is for X axis movement
float x = 0.0f;
if ( Input.Down( "Left" ) )
{
x = x - xForce;
}
if ( Input.Down( "Right" ) )
{
x = x + xForce;
}
// this is for the Z axis movement
float y = 0.0f;
if ( Input.Down( "Backward" ) )
{
y = y - zForce;
}
if ( Input.Down( "Forward" ) )
{
y = y + zForce;
}
// this is for the Y axis movement
float z = 0.0f;
if ( Input.Pressed( "Jump" ) )
{
z = yForce;
}
GameObject.WorldPosition = new Vector3( x, y, z );
}
}