Skip to content

atl/sm/physics

import "atl/sm/physics"

Physics queries and forces (sm.physics).

func ShapesInSphere(center sm.Vec3, radius float64, world sm.World) []sm.Shape
func ShapesInBox(center sm.Vec3, rotation sm.Quat, halfExtents sm.Vec3, world sm.World) []sm.Shape

Shapes overlapping a sphere / box.

func SphereHasContact(center sm.Vec3, radius float64, includeTerrain, countWater bool) bool
func SphereContactCount(center sm.Vec3, radius float64, includeTerrain, countWater bool) int

Whether anything overlaps a sphere, and how many things.

func CapsuleHasContact(from, to sm.Vec3, radius float64, mask *int) bool
func CapsuleContactCount(from, to sm.Vec3, radius float64, mask *int) int

Whether anything overlaps a capsule, and how many things.

func DistanceRaycast(start, direction sm.Vec3) (float64, bool)

A cheap ray: just the fraction (0..1) of direction travelled before a hit; false on a miss.

func IsPointInLiquid(point sm.Vec3) bool
func IsSphereInLiquid(center sm.Vec3, radius float64) bool

True if the point / sphere is in liquid.

func GroundMaterial(point sm.Vec3) string

The ground material at a point.

func MaterialID(material string) int

A physics material's id by name.

func Filter(name string) int

A raycast filter value by name (sm.physics.filter[name]).

func Gravity() float64

[server] The gravity strength.

func SetGravity(g float64)

[server] Sets the gravity strength.

func Explode(position sm.Vec3, o ExplosionOptions)

[server] Creates an explosion.

type RaycastHit struct {
Type string
Point sm.Vec3
Normal sm.Vec3
PointLocal sm.Vec3
NormalLocal sm.Vec3
Origin sm.Vec3
Direction sm.Vec3
Fraction float64
Raw atl.Value
}

What a raycast hit. Type is "body", "character", "terrainSurface", "areaTrigger", ... Point/Normal are in world space; PointLocal/NormalLocal relative to what was hit.

func ToHit(r []atl.Value) (RaycastHit, bool)

Converts the engine's (hit, result) pair to a RaycastHit; false on a miss.

func Raycast(from, to sm.Vec3, o RaycastOptions) (RaycastHit, bool)

Casts a ray from from to to; false on a miss.

func RaycastTarget(from, to sm.Vec3, target sm.Body) (RaycastHit, bool)

Casts a ray that only hits target.

func Spherecast(from, to sm.Vec3, radius float64, o RaycastOptions) (RaycastHit, bool)
func Capsulecast(from, to sm.Vec3, radius, height float64, o RaycastOptions) (RaycastHit, bool)

Casts a sphere / capsule along a line.

func Multicast(casts []Cast, world sm.World) []*RaycastHit

Runs every cast in one engine call; results are in the same order (nil for a miss).

Methods

func (h RaycastHit) Is(t string) bool

True if the hit type is t.

func (h RaycastHit) Shape() sm.Shape
func (h RaycastHit) Body() sm.Body
func (h RaycastHit) Character() sm.Character
func (h RaycastHit) Harvestable() sm.Harvestable
func (h RaycastHit) Joint() sm.Joint
func (h RaycastHit) AreaTrigger() sm.AreaTrigger

The object that was hit, when the type matches.

func (h RaycastHit) Lift() LiftHit

Reads a lift hit.

func (h RaycastHit) TerrainAssetMaterial() string

The material name of a hit terrain asset.

type LiftHit struct {
Lift sm.Lift
IsTop bool
}

A lift hit, and whether its top was hit.

type RaycastOptions struct {
Ignore sm.Body
Mask *int
}

Optional raycast settings: a body to ignore and an sm.physics.filter mask.

type Contacts struct {
Bodies []sm.Body
Characters []sm.Character
Harvestables []sm.Harvestable
Raw atl.Value
}

What overlaps a volume.

func ToContacts(t atl.Value) Contacts

Reads a contacts table.

func SphereContacts(center sm.Vec3, radius float64, mask *int) Contacts
func BoxContacts(center sm.Vec3, rotation sm.Quat, halfExtents sm.Vec3, world sm.World, mask *int) Contacts

Everything overlapping a sphere / box.

type CastKind int

The kind of a Cast.

const (
CastRay CastKind = iota
CastSphere
)
type Cast struct {
Kind CastKind
From, To sm.Vec3
Radius float64
Mask *int
IgnoreUuids []sm.Uuid
}

One cast of a multicast batch.

func Ray(from, to sm.Vec3, mask *int) Cast
func Sphere(from, to sm.Vec3, radius float64, mask *int) Cast

A ray / sphere cast.

type ExplosionOptions struct {
Level int
DestructionRadius float64
ImpulseRadius float64
Magnitude float64
Effect *string
}

Explosion settings. NewExplosionOptions gives the defaults.

func NewExplosionOptions() ExplosionOptions

The default explosion settings.