Throwing
A grabbable object that is being held by a player can be thrown with the standard controls for throwing grabbable objects on web and mobile (enabled by default). It is possible to override these standard controls in order to trigger throwing of a held object and to customize the throwing arc.
To disable the standard throwing controls you can set the Enable Throwing Controls (Web & Mobile) to off:
The properties to customize how an object is thrown are defined in a ThrowOptions object:
ThrowOptions:
* speed (optional): The speed with which to launch the object (default: 20).
* pitch (optional): Adjusts the pitch of the throw (default: 10).
* yaw (optional): Adjusts the yaw of the throw (default: 0).
* playThrowAnimation (optional): When true the throwing animation will play for web and mobile players. This will not play an animation in VR regardless of value (default: true).
* hand (optional): The hand to use for throwing (default: Handedness.Right).
You can make a player throw the object they are currently holding using throwHeldItem, with the ThrowOptions object passed as an argument. For example, to make the player throw an object when they press the primary button on web and mobile:
this.connectCodeBlockEvent(this.entity, hz.CodeBlockEvents.OnIndexTriggerDown, (player: hz.Player)=> {
// Ignore on VR devices
if (player.deviceType.get() == hz.PlayerDeviceType.VR) {
return;
}
// Setup the throw options
let opt = {
speed: 25,
pitch: 30
}
// Calling Throw Held Item
player.throwHeldItem(opt);
}