Sansar Docs
Ask or search…
K

Cannonball

Example Script: Cannonball
The example script, Cannonball _(CannonGameExample._cs), throws a cannonball from the avatar. You can get the script file from the download link at the end of the page or in the client directory: Program Files > Sansar > Client > Script API > Examples.
Instructions
Here is a step-by-step guide to using the script:
  1. 1.
    Download the script file from the download link at the end of this article.
  2. 2.
    Follow the instructions provided in Working with scripts to upload the script and add it to an object.
  3. 3.
    Open the object's Properties panel and go to the Script Settings section.
  4. 4.
    With the CannonGameExample script selected on the dropdown menu, the parameters listed in the Script Settings shows it's associate public parameters. Fill out the parameter fields based on the script's parameters as defined in this article under Script Parameters.
  5. 5.
    Once you have finished setting the parameters for your object, your script is ready! Save and build your scene.
  6. 6.
    If you want to verify that the script is running correctly, visit the scene and trigger the script by using the trigger buttons listed in this article under Script Controls.
Script parameters
Parameter Field
Description
InitialSpeed
Sets the speed at which the cannonball is thrown. The higher the value, the faster the object moves. If InitialSpeed is lower than 1.0 or greater than 200.0, then the speed defaults to 10.0.
Delay
Sets a delay on throwing the cannonball. The number entered represents the number of seconds between each throw.
Note: If a user repeatedly presses the throw button, the number of throws accumulate and will fire in succession while still considering the delay time.
Fire Sound
Assigns a sound to play when the cannon is fired.
Hit Sound
Assigns a sound to play when the cannon hits a target.
Loudness
Sets the loudness of the Fire Sound and Hit Sound when played.
Spawn Point 1
Sets teleport points. If Spawn Point values are entered, the targets that are hit randomly teleport to the designated spawn points.
Currently, you must set position points on all four points. By default, the position points <X,Y,Z> is set to <0,0,0>. Leaving <0,0,0> as a position point for any spawn point may teleport the target to <0,0,0>. You may enter the same position point values across all spawn points if you don't want the target to teleport to the <0,0,0> position point.
Spawn Point 2
Spawn Point 3
Spawn Point 4
Script controls
Use the following buttons to trigger the cannonball:
Controller
Button
Keyboard
F key
Oculus touch controllers
X button
Vive wand
N/A
Xbox controller
A button
Have more questions? Join our Discord!