Skip to content
PhysicsService

Gameplay / PhysicsService

PhysicsService Class

Collision group

Table of contents

Accessors

touchesUseCollisionGroups(): boolean other
Determine whether models set to non collision in different groups ignore touch events while ignoring collisions

Methods

addCollisionGroup(name: string): void other
Add a new collision group
boxOverlap(boxPos: Vector, boxExtent: Vector, collisionParams: CollisionQueryParams, renderParams: RenderQueryParams): GameObject[] other
Return an array of objects that overlap with the given box body
boxTraceMulti(start: Vector, end: Vector, halfSize: Vector, orientation: Rotation, collisionParams: CollisionQueryParams, renderParams: RenderQueryParams): HitResult[] other
Scan a box along a given route and return all hits encountered, including the first interception hit.
boxTraceSingle(start: Vector, end: Vector, halfSize: Vector, orientation: Rotation, collisionParams: CollisionQueryParams, renderParams: RenderQueryParams): HitResult other
Scan a box along a given line and return the first obstruction hit encountered.
capsuleOverlap(capsulePos: Vector, radius: number, halfHeight: number, collisionParams: CollisionQueryParams, renderParams: RenderQueryParams): GameObject[] other
Return an array of objects that overlap with the given capsule body
capsuleTraceMulti(start: Vector, end: Vector, radius: number, halfHeight: number, collisionParams: CollisionQueryParams, renderParams: RenderQueryParams): HitResult[] other
Scan a capsule along a given route and return all hits encountered, including the first interception hit.
capsuleTraceSingle(start: Vector, end: Vector, radius: number, halfHeight: number, collisionParams: CollisionQueryParams, renderParams: RenderQueryParams): HitResult other
Scan a capsule along a given line and return the first obstruction hit encountered.
deleteCollisionGroup(name: string): void other
Delete existing collision groups
getAvailableCollisionGroupsCount(): number other
Get the current number of available collision groups
getCollisionBetweenGroups(group1: string, group2: string): boolean other
Obtain the collision relationship between two collision groups (whether collision can occur)
getValidCollisionGroups(): string[] other
Retrieve the list of currently added collision group names
isCollisionGroupValid(name: string): boolean other
Whether the detect collision group is valid (added)
lineTraceMulti(start: Vector, end: Vector, collisionParams: CollisionQueryParams, renderParams: RenderQueryParams): HitResult[] other
Perform collision tracking along the given line and return all hits encountered until and including the first blocking hit.
lineTraceSingle(start: Vector, end: Vector, collisionParams: CollisionQueryParams, renderParams: RenderQueryParams): HitResult other
Perform collision tracking along the given line and return the first obstacle hit encountered.
renameCollisionGroup(previousName: string, newName: string): void other
Rename a collision group
setCollisionBetweenGroups(group1: string, group2: string, collidable: boolean): void other
Set the collision relationship between two collision groups (whether collisions can occur)
sphereOverlap(spherePos: Vector, sphereRadius: number, collisionParams: CollisionQueryParams, renderParams: RenderQueryParams): GameObject[] other
Return an array of objects that overlap with the given sphere
sphereTraceMulti(start: Vector, end: Vector, radius: number, collisionParams: CollisionQueryParams, renderParams: RenderQueryParams): HitResult[] other
Scan a sphere along a given straight line and return all hits, including the first interception hit.
sphereTraceSingle(start: Vector, end: Vector, radius: number, collisionParams: CollisionQueryParams, renderParams: RenderQueryParams): HitResult other
Scan a sphere along a given line and return the first obstruction hit encountered.

Accessors

touchesUseCollisionGroups

Static get touchesUseCollisionGroups(): boolean other

Static set touchesUseCollisionGroups(status): void other

Determine whether models set to non collision in different groups ignore touch events while ignoring collisions

Returns

booleanDoes the model set as non collision in different groups ignore both collision and touch events

Determine whether models set to non collision in different groups ignore touch events while ignoring collisions

Usage example: Create a script named TouchesUseCollisionGroups in the scene, drag it into the scene, and copy the following code into the script. After press 1 and 2, the server will call the onTouch function and output the corresponding LOG.

ts
@Component
export default class TouchesUseCollisionGroups extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.touchesUseCollisionGroups = true;
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create normal collision sphere A and set collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            this.serverCreateBall(new Vector(300, 0, 0), "GroupA", false);
        })

        // Create a simulated physical sphere B and set the collision group to GroupB
        InputUtil.onKeyDown(Keys.Two, ()=>{
            this.serverCreateBall(new Vector(300, 0, 100), "GroupB", true);
        })
    }

    @mw.RemoteFunction(mw.Server)
    serverCreateBall(pos:Vector, Group:string, bPhysicsSimulate:boolean)
    {
        GameObject.asyncSpawn("197388", {replicates:true}).then((obj)=>{
            let ball  = obj as mw.Model;
            ball.worldTransform.position = pos;
            if (bPhysicsSimulate)
            {
                ball.physicsEnabled = true;
                ball.massEnabled = true;
                ball.mass = 50;
            }
            ball.collisionGroup = Group;
            ball.onTouch.add((obj : GameObject) => {
                console.log(`${obj.gameObjectId} - Touch - ${ball.gameObjectId}`);
            }
        );
        })
    }
}
@Component
export default class TouchesUseCollisionGroups extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.touchesUseCollisionGroups = true;
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create normal collision sphere A and set collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            this.serverCreateBall(new Vector(300, 0, 0), "GroupA", false);
        })

        // Create a simulated physical sphere B and set the collision group to GroupB
        InputUtil.onKeyDown(Keys.Two, ()=>{
            this.serverCreateBall(new Vector(300, 0, 100), "GroupB", true);
        })
    }

    @mw.RemoteFunction(mw.Server)
    serverCreateBall(pos:Vector, Group:string, bPhysicsSimulate:boolean)
    {
        GameObject.asyncSpawn("197388", {replicates:true}).then((obj)=>{
            let ball  = obj as mw.Model;
            ball.worldTransform.position = pos;
            if (bPhysicsSimulate)
            {
                ball.physicsEnabled = true;
                ball.massEnabled = true;
                ball.mass = 50;
            }
            ball.collisionGroup = Group;
            ball.onTouch.add((obj : GameObject) => {
                console.log(`${obj.gameObjectId} - Touch - ${ball.gameObjectId}`);
            }
        );
        })
    }
}

Parameters

status booleanUsage: Whether models in different groups that are set to not collision ignore collision while ignoring touch events range: unlimited

Methods

addCollisionGroup

Static addCollisionGroup(name): void other

Add a new collision group

Parameters

name stringUsage: collision group name range: unlimited

Usage example: create a script named CollisionGroup in the scene, drag it into the scene, and copy the following code into the script. Press 1 to see the output "GroupA, GroupB, GroupC" in the editor window client

ts
@Component
export default class CollisionGroup extends Script {

    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            PhysicsService.addCollisionGroup("GroupC");
            console.log(PhysicsService.getValidCollisionGroups());
        })
    }
}
@Component
export default class CollisionGroup extends Script {

    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            PhysicsService.addCollisionGroup("GroupC");
            console.log(PhysicsService.getValidCollisionGroups());
        })
    }
}

boxOverlap

Static boxOverlap(boxPos, boxExtent, collisionParams, renderParams): GameObject[] other

Return an array of objects that overlap with the given box body

Parameters

boxPos VectorUsage: detect position
boxExtent VectorUsage: Box size
collisionParams CollisionQueryParamsUsage: Collision query rendering parameters
renderParams RenderQueryParamsUsage: Spatial query rendering parameters

Returns

GameObject[]GameObject array

Usage example: The following example shows the basic process of using rectangle range detect

ts
const result = PhysicsService.boxOverlap(new mw.Vector(0,0,0), new Vector(30, 30, 30), {}, {});
for (const item of result) {
    // item:  Test results.
}
const result = PhysicsService.boxOverlap(new mw.Vector(0,0,0), new Vector(30, 30, 30), {}, {});
for (const item of result) {
    // item:  Test results.
}

boxTraceMulti

Static boxTraceMulti(start, end, halfSize, orientation, collisionParams, renderParams): HitResult[] other

Scan a box along a given route and return all hits encountered, including the first interception hit.

Parameters

start Vectorstarting point
end VectorUsage: Termination Point
halfSize VectorBox size
orientation RotationRotation size
collisionParams CollisionQueryParamsUsage: Spatial query collision parameters
renderParams RenderQueryParamsUsage: Spatial query rendering parameters

Returns

HitResult[]HitResult array

Usage example: The following example shows the basic process of using rectangle range detect

ts
const result = PhysicsService.boxTraceMulti(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), new Vector(30, 30, 30), new Rotation(45, 45, 45), {}, {});
for (const item of result) {
    // item:  Test results.
}
const result = PhysicsService.boxTraceMulti(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), new Vector(30, 30, 30), new Rotation(45, 45, 45), {}, {});
for (const item of result) {
    // item:  Test results.
}

boxTraceSingle

Static boxTraceSingle(start, end, halfSize, orientation, collisionParams, renderParams): HitResult other

Scan a box along a given line and return the first obstruction hit encountered.

Parameters

start Vectorstarting point
end VectorUsage: Termination Point
halfSize VectorBox size
orientation RotationRotation size
collisionParams CollisionQueryParamsUsage: Spatial query collision parameters
renderParams RenderQueryParamsUsage: Spatial query rendering parameters

Returns

HitResultHitResult

Usage example: The following example shows the basic process of using rectangle range detect

ts
const result = PhysicsService.boxTraceSingle(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), new Vector(30, 30, 30), new Rotation(45, 45, 45), {}, {});
const result = PhysicsService.boxTraceSingle(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), new Vector(30, 30, 30), new Rotation(45, 45, 45), {}, {});

capsuleOverlap

Static capsuleOverlap(capsulePos, radius, halfHeight, collisionParams, renderParams): GameObject[] other

Return an array of objects that overlap with the given capsule body

Parameters

capsulePos VectorUsage: detect position
radius numberCapsule body radius
halfHeight numberUsage: Half height of capsule body
collisionParams CollisionQueryParamsUsage: Collision query rendering parameters
renderParams RenderQueryParamsUsage: Spatial query rendering parameters

Returns

GameObject[]GameObject array

Usage example: The following example shows the basic process of using rectangle range detect

ts
const result = PhysicsService.capsuleOverlap(new mw.Vector(0,0,0), 30, 80, {}, {});
for (const item of result) {
    // item:  Test results.
}
const result = PhysicsService.capsuleOverlap(new mw.Vector(0,0,0), 30, 80, {}, {});
for (const item of result) {
    // item:  Test results.
}

capsuleTraceMulti

Static capsuleTraceMulti(start, end, radius, halfHeight, collisionParams, renderParams): HitResult[] other

Scan a capsule along a given route and return all hits encountered, including the first interception hit.

Parameters

start Vectorstarting point
end VectorUsage: Termination Point
radius numberCapsule body radius
halfHeight numberHalf height of capsule body
collisionParams CollisionQueryParamsUsage: Spatial query collision parameters
renderParams RenderQueryParamsUsage: Spatial query rendering parameters

Returns

HitResult[]HitResult array

Usage example: The following example shows the basic process of using rectangle range detect

ts
const result = PhysicsService.capsuleTraceMulti(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), 30, 80, {}, {});
for (const item of result) {
    // item:  Test results.
}
const result = PhysicsService.capsuleTraceMulti(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), 30, 80, {}, {});
for (const item of result) {
    // item:  Test results.
}

capsuleTraceSingle

Static capsuleTraceSingle(start, end, radius, halfHeight, collisionParams, renderParams): HitResult other

Scan a capsule along a given line and return the first obstruction hit encountered.

Parameters

start Vectorstarting point
end VectorUsage: Termination Point
radius numberCapsule body radius
halfHeight numberHalf height of capsule body
collisionParams CollisionQueryParamsUsage: Spatial query collision parameters
renderParams RenderQueryParamsUsage: Spatial query rendering parameters

Returns

HitResultHitResult

Usage example: The following example shows the basic process of using rectangle range detect

ts
const result = PhysicsService.capsuleTraceSingle(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), 30, 80, {}, {});
const result = PhysicsService.capsuleTraceSingle(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), 30, 80, {}, {});

deleteCollisionGroup

Static deleteCollisionGroup(name): void other

Delete existing collision groups

Parameters

name stringUsage: collision group name range: unlimited

Usage example: Create a script called CollisionGroup in the scene, drag it into the scene, and copy the following code into the script. Press 1 to see the output "GroupB" in the editor window client

ts
@Component
export default class CollisionGroup extends Script {

    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            PhysicsService.deleteCollisionGroup("GroupA");
            console.log(PhysicsService.getValidCollisionGroups());
        })
    }

    protected onUpdate(dt: number): void {

    }

    // Call this function after the last frame is executed when the script is destroyed
    protected onDestroy(): void {

    }
}
@Component
export default class CollisionGroup extends Script {

    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            PhysicsService.deleteCollisionGroup("GroupA");
            console.log(PhysicsService.getValidCollisionGroups());
        })
    }

    protected onUpdate(dt: number): void {

    }

    // Call this function after the last frame is executed when the script is destroyed
    protected onDestroy(): void {

    }
}

getAvailableCollisionGroupsCount

Static getAvailableCollisionGroupsCount(): number other

Get the current number of available collision groups

Returns

numberRemaining number of available collision groups

Usage example: Create a script called CollisionGroup in the scene, drag it into the scene, and copy the following code into the script. After pressing 1, you can see the output "8" in the editor window client

ts
@Component
export default class CollisionGroup extends Script {

    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            console.log(PhysicsService.getAvailableCollisionGroupsCount());
        })
    }
}
@Component
export default class CollisionGroup extends Script {

    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            console.log(PhysicsService.getAvailableCollisionGroupsCount());
        })
    }
}

getCollisionBetweenGroups

Static getCollisionBetweenGroups(group1, group2): boolean other

Obtain the collision relationship between two collision groups (whether collision can occur)

Parameters

group1 stringUsage: Collision group name 1 range: Unrestricted
group2 stringUsage: collision group name 2 range: unlimited

Returns

booleanCollision relationship (whether collision can occur)

Usage example: Create a script called CollisionGroup in the scene, drag it into the scene, and copy the following code into the script. After pressing 1, you can see the output 'false' in the editor window client

ts
@Component
export default class CollisionGroup extends Script {

    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            console.log(PhysicsService.getCollisionBetweenGroups("GroupA", "GroupB"));
        })
    }
}
@Component
export default class CollisionGroup extends Script {

    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            console.log(PhysicsService.getCollisionBetweenGroups("GroupA", "GroupB"));
        })
    }
}

getValidCollisionGroups

Static getValidCollisionGroups(): string[] other

Retrieve the list of currently added collision group names

Returns

string[]List of currently added collision group names

Usage example: create a script named CollisionGroup in the scene, drag it into the scene, and copy the following code into the script. Press 1 to see the output "GroupA, GroupB" in the editor window client

ts
@Component
export default class CollisionGroup extends Script {

    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            console.log(PhysicsService.getValidCollisionGroups());
        })
    }
}
@Component
export default class CollisionGroup extends Script {

    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            console.log(PhysicsService.getValidCollisionGroups());
        })
    }
}

isCollisionGroupValid

Static isCollisionGroupValid(name): boolean other

Whether the detect collision group is valid (added)

Parameters

name stringUsage: collision group name range: unlimited

Returns

booleanWhether the collision group is valid

Usage example: create a script named CollisionGroup in the scene, drag it into the scene, and copy the following code into the script. After pressing 1, you can see the output 'false' in the editor window client

ts
@Component
export default class CollisionGroup extends Script {

    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            console.log(PhysicsService.isCollisionGroupValid("GroupC"));
        })
    }
}
@Component
export default class CollisionGroup extends Script {

    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            console.log(PhysicsService.isCollisionGroupValid("GroupC"));
        })
    }
}

lineTraceMulti

Static lineTraceMulti(start, end, collisionParams, renderParams): HitResult[] other

Perform collision tracking along the given line and return all hits encountered until and including the first blocking hit.

Parameters

start Vectorstarting point
end VectorUsage: Termination Point
collisionParams CollisionQueryParamsUsage: Spatial query collision parameters
renderParams RenderQueryParamsUsage: Spatial query rendering parameters

Returns

HitResult[]HitResult array

Usage example: The following example shows the basic process of using rectangle range detect

ts
const result = PhysicsService.lineTraceMulti(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), {}, {});
for (const item of result) {
    // item:  Test results.
}
const result = PhysicsService.lineTraceMulti(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), {}, {});
for (const item of result) {
    // item:  Test results.
}

lineTraceSingle

Static lineTraceSingle(start, end, collisionParams, renderParams): HitResult other

Perform collision tracking along the given line and return the first obstacle hit encountered.

Parameters

start Vectorstarting point
end VectorUsage: Termination Point
collisionParams CollisionQueryParamsUsage: Spatial query collision parameters
renderParams RenderQueryParamsUsage: Spatial query rendering parameters

Returns

HitResultHitResult

Usage example: The following example shows the basic process of using rectangle range detect

ts
const result = PhysicsService.lineTraceSingle(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), {}, {});
const result = PhysicsService.lineTraceSingle(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), {}, {});

renameCollisionGroup

Static renameCollisionGroup(previousName, newName): void other

Rename a collision group

Parameters

previousName stringUsage: collision group name range: unlimited
newName stringUsage: New collision group name range: Unrestricted

Usage example: create a script named CollisionGroup in the scene, drag it into the scene, and copy the following code into the script. After pressing 1, you can see the output "GroupB, GroupC" in the editor window client

ts
@Component
export default class CollisionGroup extends Script {

    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            PhysicsService.renameCollisionGroup("GroupA","GroupC");
            console.log(PhysicsService.getValidCollisionGroups());
        })
    }

    protected onUpdate(dt: number): void {

    }

    // Call this function after the last frame is executed when the script is destroyed
    protected onDestroy(): void {

    }
}
@Component
export default class CollisionGroup extends Script {

    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            PhysicsService.renameCollisionGroup("GroupA","GroupC");
            console.log(PhysicsService.getValidCollisionGroups());
        })
    }

    protected onUpdate(dt: number): void {

    }

    // Call this function after the last frame is executed when the script is destroyed
    protected onDestroy(): void {

    }
}

setCollisionBetweenGroups

Static setCollisionBetweenGroups(group1, group2, collidable): void other

Set the collision relationship between two collision groups (whether collisions can occur)

Parameters

group1 stringUsage: collision group name 1 range: unlimited
group2 stringUsage: Collision group name 2 range: Unrestricted
collidable booleanUsage: Can collision occur

Usage example: Create a script called CollisionGroup in the scene, drag it into the scene, and copy the following code into the script. Press 1 and 2 to see two balls generate in the scene, and push the nearest ball to hit the other. It will be found that Player can collision with the ball, but the two balls can penetrate.

ts
@Component
export default class CollisionGroup extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            this.serverCreateBall(new Vector(300, 0, 0), "GroupA", true);
        })

        // Create sphere B with normal collision and set the collision group to GroupB
        InputUtil.onKeyDown(Keys.Two, ()=>{
            this.serverCreateBall(new Vector(600, 0, 0), "GroupB", false);
        })
    }

    @mw.RemoteFunction(mw.Server)
    serverCreateBall(pos:Vector, Group:string, bPhysicsSimulate:boolean)
    {
        GameObject.asyncSpawn("197388", {replicates:true}).then((obj)=>{
            let ball  = obj as mw.Model;
            ball.worldTransform.position = pos;
            if (bPhysicsSimulate)
            {
                ball.physicsEnabled = true;
                ball.massEnabled = true;
                ball.mass = 50;
            }
            ball.collisionGroup = Group;
        })
    }
}
@Component
export default class CollisionGroup extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        PhysicsService.addCollisionGroup("GroupA");
        PhysicsService.addCollisionGroup("GroupB");
        PhysicsService.setCollisionBetweenGroups("GroupA", "GroupB", false);

        // Create the sphere A simulating physics and set the collision group as GroupA
        InputUtil.onKeyDown(Keys.One, ()=>{
            this.serverCreateBall(new Vector(300, 0, 0), "GroupA", true);
        })

        // Create sphere B with normal collision and set the collision group to GroupB
        InputUtil.onKeyDown(Keys.Two, ()=>{
            this.serverCreateBall(new Vector(600, 0, 0), "GroupB", false);
        })
    }

    @mw.RemoteFunction(mw.Server)
    serverCreateBall(pos:Vector, Group:string, bPhysicsSimulate:boolean)
    {
        GameObject.asyncSpawn("197388", {replicates:true}).then((obj)=>{
            let ball  = obj as mw.Model;
            ball.worldTransform.position = pos;
            if (bPhysicsSimulate)
            {
                ball.physicsEnabled = true;
                ball.massEnabled = true;
                ball.mass = 50;
            }
            ball.collisionGroup = Group;
        })
    }
}

sphereOverlap

Static sphereOverlap(spherePos, sphereRadius, collisionParams, renderParams): GameObject[] other

Return an array of objects that overlap with the given sphere

Parameters

spherePos VectorUsage: detect position
sphereRadius numberUsage: sphere radius
collisionParams CollisionQueryParamsUsage: Collision query rendering parameters
renderParams RenderQueryParamsUsage: Spatial query rendering parameters

Returns

GameObject[]GameObject array

Usage example: The following example shows the basic process of using rectangle range detect

ts
const result = PhysicsService.sphereOverlap(new mw.Vector(0,0,0), 30, {}, {});
for (const item of result) {
    // item:  Test results.
}
const result = PhysicsService.sphereOverlap(new mw.Vector(0,0,0), 30, {}, {});
for (const item of result) {
    // item:  Test results.
}

sphereTraceMulti

Static sphereTraceMulti(start, end, radius, collisionParams, renderParams): HitResult[] other

Scan a sphere along a given straight line and return all hits, including the first interception hit.

Parameters

start Vectorstarting point
end VectorUsage: Termination Point
radius numberSpherical radius
collisionParams CollisionQueryParamsUsage: Spatial query collision parameters
renderParams RenderQueryParamsUsage: Spatial query rendering parameters

Returns

HitResult[]HitResult array

Usage example: The following example shows the basic process of using rectangle range detect

ts
const result = PhysicsService.sphereTraceMulti(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), 30, {}, {});
for (const item of result) {
    // item:  Test results.
}
const result = PhysicsService.sphereTraceMulti(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), 30, {}, {});
for (const item of result) {
    // item:  Test results.
}

sphereTraceSingle

Static sphereTraceSingle(start, end, radius, collisionParams, renderParams): HitResult other

Scan a sphere along a given line and return the first obstruction hit encountered.

Parameters

start Vectorstarting point
end VectorUsage: Termination Point
radius numberSpherical radius
collisionParams CollisionQueryParamsUsage: Spatial query collision parameters
renderParams RenderQueryParamsUsage: Spatial query rendering parameters

Returns

HitResultHitResult

Usage example: The following example shows the basic process of using rectangle range detect

ts
const result = PhysicsService.sphereTraceSingle(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), 30, {}, {});
const result = PhysicsService.sphereTraceSingle(new mw.Vector(0,0,0), new mw.Vector(1000,0,0), 30, {}, {});