Gameplay / Impulse
Impulse Class
Impulse
Impulse is an instant explosive force, which provides a single and instant power supply for the object, and it is a feeling of concentrating the force on a frame.
How does the Impulse Object work?
Create a Impulse Object. You can manually drag the impulse in the logical object in the left column into the scene, and adjust the parameters in the property panel; You can also dynamically create impulse objects in the script.
Set the property enable of the Impulse Object to true to trigger the impulse effect.
impulseVector Attribute represents the direction of force.
impulseRadialForce The property represents the magnitude of the force.
Usage example: create a script named "ImpulseSample", place it in the child of the Impulse Object in the Object Manager, change the relative scale of the Impulse Object to (5.00, 5.00, 0.50), place it in an appropriate position, and place a Cube in the overlapping area of the Impulse Object. The size of the Cube scale is the same as that of the Impulse Object. Open the script, enter the following code to save, run the game, and you will see the effect of the character bouncing on the Cube in the scene. The code is as follows: (In the example code where impulseId="1602E908", the replacement method for 1602E908 is to right-click on the impulse object and copy the object ID. Replace it with your impulse object ID.)
@Component
export default class ImpulseSample extends Script {
impulseId = "1602E908";
// When the script is instantiated, this function will be called before the first frame update
protected async onStart(): Promise<void> {
const impulse = (await GameObject.findGameObjectById(this.impulseId)) as Impulse;
// First set it to false, then set it to true after the Player enters the range, and the Player will be suddenly bounced away
impulse.enable = true;
// When applying absolute impulse, the object's own velocity will be cleared first, while relative impulse will superimpose the impulse with the current velocity of the object
impulse.impulseType = ImpulseType.Absolute;
// The impulseVector property is meaningful only when it is a vector force
impulse.impulseForceType = ImpulseForceType.VectorForce;
// Set as custom impulse value with direction
impulse.impulseVector = new Vector(0, 0, 2000);
impulse.onImpulseEnter.add(()=>{
console.log("Impulse onImpulseEnter")
})
}
}
@Component
export default class ImpulseSample extends Script {
impulseId = "1602E908";
// When the script is instantiated, this function will be called before the first frame update
protected async onStart(): Promise<void> {
const impulse = (await GameObject.findGameObjectById(this.impulseId)) as Impulse;
// First set it to false, then set it to true after the Player enters the range, and the Player will be suddenly bounced away
impulse.enable = true;
// When applying absolute impulse, the object's own velocity will be cleared first, while relative impulse will superimpose the impulse with the current velocity of the object
impulse.impulseType = ImpulseType.Absolute;
// The impulseVector property is meaningful only when it is a vector force
impulse.impulseForceType = ImpulseForceType.VectorForce;
// Set as custom impulse value with direction
impulse.impulseVector = new Vector(0, 0, 2000);
impulse.onImpulseEnter.add(()=>{
console.log("Impulse onImpulseEnter")
})
}
}
Hierarchy
↳
Impulse
Table of contents
Properties
onImpulseEnter: MulticastGameObjectDelegate |
---|
Callback function after impulse collision |
click
Properties
onBeforeDestroyDelegate: MulticastDelegate <() => void > other |
---|
Event callback before object destruction |
onCustomPropertyChange: Readonly <MulticastDelegate <(path : string , value : unknown , oldValue : unknown ) => void >> other |
Monitor custom attribute synchronization events |
onDestroyDelegate: MulticastDelegate <() => void > other |
Event callback after object destruction |
onPropertyChange: Readonly <MulticastDelegate <(path : string , value : unknown , oldValue : unknown ) => void >> |
Monitor system replicated events |
Accessors
enable(): boolean other |
---|
Get whether to enable impulse |
impulseForceType(): ImpulseForceType other |
Get the current punching force type |
impulseRadialForce(): number other |
Obtain the impulse value of radial force |
impulseType(): ImpulseType other |
Get impulse application mode, absolute or relative |
impulseVector(): Vector other |
Obtain the impulse vector of the vector force |
click
Accessors
actorFlagValue(): number other |
---|
Get object tags |
actorLevel(): number other |
Obtain Actor Level |
assetId(): string other |
Retrieve the UID of the resource currently being used by the object |
gameObjectId(): string other |
Get the unique identification of an object (a string that uniquely identifies an object). |
isDestroyed(): boolean other |
Has the current object been destroyed |
isReady(): boolean other |
Current object status |
localTransform(): Transform other |
Local transformation of the current object |
name(): string other |
Return the current object name |
netStatus(): NetStatus other |
Get the current object synchronization status |
parent(): GameObject other |
Retrieve the current parent object |
tag(): string other |
Get the tag of the current object |
worldTransform(): Transform other |
Current object world transformation |
Methods
click
Methods
addComponent<T : extends Script <T >>(constructor : (...args : unknown []) => T : extends Script <T >, bInReplicates? : boolean ): T : extends Script <T > other |
---|
Add a script component |
asyncGetChildByName(name : string ): Promise <GameObject > other |
Asynchronous search for sub objects based on their names |
asyncReady(): Promise <GameObject > other |
Return after the object is ready |
clone(gameObjectInfo? : GameObjectInfo ): GameObject other |
Copy Objects |
destroy(): void other |
delete object |
getBoundingBox(nonColliding? : boolean , includeFromChild? : boolean , outer? : Vector ): Vector other |
Get the size of the object's bounding box |
getBounds(onlyCollidingComponents : boolean , originOuter : Vector , boxExtentOuter : Vector , includeFromChild? : boolean ): void other |
Obtain object boundaries |
getChildByGameObjectId(gameObjectId : string ): GameObject other |
Search for sub objects based on gameObjectid |
getChildByName(name : string ): GameObject other |
Search for sub objects by name |
getChildByPath(path : string ): GameObject other |
Find sub objects according to path |
getChildren(): GameObject [] other |
Obtain sub objects |
getChildrenBoundingBoxCenter(outer? : Vector ): Vector other |
Get the center point of all child objects' bounding box (not including the parent object, if the parent object is unavailable, return [0,0,0]) |
getChildrenByName(name : string ): GameObject [] other |
Search for all sub objects by name |
getComponent<T : extends Script <T >>(constructor? : (...args : unknown []) => T : extends Script <T >): T : extends Script <T > other |
Get the component of the specified type |
getComponentPropertys<T : extends Script <T >>(constructor : (...args : unknown []) => T : extends Script <T >): Map <string , IPropertyOptions > other |
Get property of script component |
getComponents<T : extends Script <T >>(constructor? : (...args : unknown []) => T : extends Script <T >): T : extends Script <T >[] other |
Get all component of the specified type |
getCustomProperties(): string [] other |
Get all customize property |
getCustomProperty<T : extends CustomPropertyType >(propertyName : string ): T : extends CustomPropertyType other |
Get customize property |
getCustomPropertyChangeDelegate(property ): Readonly <MulticastDelegate <(path : string , value : unknown , oldValue : unknown ) => void >> other |
Event proxy triggered when a given object property is modified |
getPropertyChangeDelegate(property ): Readonly <MulticastDelegate <(path : string , value : unknown , oldValue : unknown ) => void >> other |
Event proxy triggered when a given object property is modified |
getVisibility(): boolean other |
Obtain whether the object is displayed |
isPrefabActor(): boolean other |
Return whether the current object is a prefabricated body |
moveBy(velocity : Vector , isLocal? : boolean ): void other |
Smoothly move an object over time according to a given velocity vector |
moveTo(targetPosition : Vector , time : number , isLocal? : boolean , onComplete? : () => void ): void other |
Smoothly move from the current position to the target position within the specified time |
rotateBy(rotation : Quaternion Rotation , multiplier : number , isLocal? : boolean ): void other |
Rotate the object smoothly over time according to the given rotation amount |
rotateTo(targetRotation : Quaternion Rotation , time : number , isLocal? : boolean , onComplete? : () => void ): void other |
Smoothly changes from the current rotation to the target rotation within the specified time |
scaleBy(scale : Vector , isLocal? : boolean ): void other |
Smoothly scale objects over time using a given scaling vector per second |
scaleTo(targetScale : Vector , time : number , isLocal? : boolean , onComplete? : () => void ): void other |
Smoothly changes from the current scale to the target scale within the specified time |
setAbsolute(absolutePosition? : boolean , absoluteRotation? : boolean , absoluteScale? : boolean ): void other |
Set whether the object localTransform is relative to the parent object or the world |
setCustomProperty(propertyName : string , value : undefined CustomPropertyType ): void other |
Set custom attributes |
setVisibility(status : boolean PropertyStatus , propagateToChildren? : boolean ): void other |
Set whether the object is displayed |
stopMove(): void other |
Interrupt further movement of moveTo() and moveBy() |
stopRotate(): void other |
Interrupt further rotation from rotateTo() or rotateBy() |
stopScale(): void other |
Interrupt further scale from ScaleTo() or ScaleBy() |
asyncFindGameObjectById(gameObjectId : string ): Promise <GameObject > other |
Asynchronous search for GameObject through gameObjectid |
asyncGetGameObjectByPath(path : string ): Promise <GameObject > other |
Asynchronously find objects through path |
asyncSpawn<T : extends GameObject <T >>(assetId : string , gameObjectInfo? : GameObjectInfo ): Promise <T : extends GameObject <T >> other |
Asynchronous construction of an object |
bulkPivotTo(gameObjects : GameObject [], transforms : Transform []): void other |
Batch set position |
findGameObjectById(gameObjectId : string ): GameObject other |
Search for objects through gameObjectid |
findGameObjectByName(name : string ): GameObject other |
Search for objects by name |
findGameObjectsByName(name : string ): GameObject [] other |
Search for objects by name |
findGameObjectsByTag(tag : string ): GameObject [] other |
Get objects through customize tag |
getGameObjectByPath(path : string ): GameObject other |
Search for objects through paths |
spawn<T : extends GameObject <T >>(assetId : string , gameObjectInfo? : GameObjectInfo ): T : extends GameObject <T > other |
Construct an object |
Properties
onImpulseEnter
• onImpulseEnter: MulticastGameObjectDelegate
Callback function after impulse collision
Example usage: Create a script called "ImpulseOnInterSample", place it in the object manager, open the script, enter the following code to save, run the game, and you will see a trampoline effect in the scene. The code is as follows:
@Component
export default class ImpulseOnEnterSample extends Script {
impulseId = "1602E908";
// When the script is instantiated, this function will be called before the first frame update
protected async onStart(): Promise<void> {
const impulse = (await GameObject.findGameObjectById(this.impulseId)) as Impulse;
impulse.onImpulseEnter.add(()=>{
console.log("Impulse onImpulseEnter")
})
}
}
@Component
export default class ImpulseOnEnterSample extends Script {
impulseId = "1602E908";
// When the script is instantiated, this function will be called before the first frame update
protected async onStart(): Promise<void> {
const impulse = (await GameObject.findGameObjectById(this.impulseId)) as Impulse;
impulse.onImpulseEnter.add(()=>{
console.log("Impulse onImpulseEnter")
})
}
}
Accessors
enable
• | • | ||||
---|---|---|---|---|---|
Get whether to enable impulse Returns
| Set whether to enable impulse. Under disable status, impulse will not be applied to objects Example usage: Create a script called "ImpulseSample", place it in the object manager, open the script, enter the following code to save, run the game, and you will see a trampoline effect in the scene. The code is as follows: ts
Parameters
|
impulseForceType
• | • | ||||
---|---|---|---|---|---|
Get the current punching force type Returns
| Sets the impulse force type. See the example code in the property impulseRadialForce and impulseVector for the usage example. Parameters
|
impulseRadialForce
• | • | ||||
---|---|---|---|---|---|
Obtain the impulse value of radial force Returns
| Set the impulse value of the radial force Usage example: create a script named "ImplemenseRadicalForceSample", place it in the object manager, open the script, enter the following code to save it, run the game, and you will see the effect of a trampoline in the scene. The distance that Player are flying on the trampoline changes compared to the default situation. The code is as follows: ts
Parameters
|
impulseType
• | • | ||||
---|---|---|---|---|---|
Get impulse application mode, absolute or relative Returns
| Set impulse application method Precautions Use in the editor will automatically update the arrow direction Usage example: Create a script called "ImpulseTypeSample", place it in the object manager, open the script, enter the following code to save, run the game, and you will see a trampoline effect in the scene. The height of the trampoline that the player is bounced up when they walk on it changes. The code is as follows: ts
Parameters
|
impulseVector
• | • | ||||
---|---|---|---|---|---|
Obtain the impulse vector of the vector force Returns
| Set the impulse vector of the vector force Usage example: create a script named "ImplemenseVectorSample", place it in the object manager, open the script, enter the following code to save it, run the game, and you will see the effect of a trampoline in the scene. The height of the bounce on the trampoline of Player will change. The code is as follows: ts
Parameters
|