Property | Setting |
---|---|
Motion | Set to Interactive . |
Interaction | Set to Physics or Both . |
Gravity | Enable it. |
World.onUpdate
loop. For more information about this event, see World Update Events.springPushTowardPosition()
function referenceAction
Parameters
position
[Vec3] - The target position, or “origin” of the spring.options
[(Optional) SpringOptions
] - An object to configure the spring’s behavior.
stiffness
- The amount of force applied to the object.damping
- Ratio to control the spring’s oscillations.Returns
import * as hz from 'horizon/core';
class SpringTest extends hz.Component<typeof SpringTest> {
static propsDefinition = {
translateObj: {type: hz.PropTypes.Entity},
translatePos: {type: hz.PropTypes.Vec3, default: new hz.Vec3 (1,0,20)},
translateStiffness: {type: hz.PropTypes.Number, default: 2},
translateDamping: {type: hz.PropTypes.Number, default: 0.9},
};
start() {
var varTranslateObj = this.props.translateObj!.as(hz.PhysicalEntity);
if (varTranslateObj) {
var varTranslatePos = this.props.translatePos
var varTranslateStiffness = this.props.translateStiffness
var varTranslateDamping = this.props.translateDamping
var varTranslateOptions = {stiffness: varTranslateStiffness, damping: varTranslateDamping}
}
this.connectLocalBroadcastEvent(hz.World.onUpdate, (data: {deltaTime: number}) => {
if (this.props.translateObj) {
varTranslateObj.springPushTowardPosition(varTranslatePos, varTranslateOptions)
};
});
};
};
hz.Component.register(SpringTest);
springSpinTowardRotation()
function referenceAction
Parameters
position
[Vec3] - The target position, or “origin” of the spring.options
[(Optional) SpringOptions
] - An object to configure the spring’s behavior.
stiffness
- The amount of force applied on the object.damping
- Ratio to control the spring’s oscillations.axisIndependent
- Ensures the object’s motion is parallel to the push direction.Returns
import * as hz from 'horizon/core';
class SpinTest extends hz.Component<typeof SpinTest> {
static propsDefinition = {
rotateObj: {type: hz.PropTypes.Entity},
rotatePos: {type: hz.PropTypes.Vec3, default: new hz.Vec3 (90,90,90)},
rotateStiffness: {type: hz.PropTypes.Number, default: 10},
rotateDamping: {type: hz.PropTypes.Number, default: 0.9},
rotateAxisIndependent: {type:hz.PropTypes.Boolean, default: true}
};
start() {
var varRotateObj = this.props.rotateObj!.as(hz.PhysicalEntity);
if (varRotateObj) {
var varRotatePos = this.props.rotatePos!
var varRotateStiffness = this.props.rotateStiffness
var varRotateDamping = this.props.rotateDamping
var varRotateAxisIndependent = this.props.rotateAxisIndependent
var varRotateOptions = {stiffness: varRotateStiffness, damping: varRotateDamping, axisIndependent: varRotateAxisIndependent}
};
this.connectLocalBroadcastEvent(hz.World.onUpdate, (data: {deltaTime: number}) => {
if (varRotateObj) {
varRotateObj.springSpinTowardRotation(hz.Quaternion.fromVec3(varRotatePos), varRotateOptions)
};
});
};
};
hz.Component.register(SpinTest);