Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This work uses content from the Sansar Knowledge Base. © 2017 Linden Research, Inc.
- Licensed under the Creative Commons Attribution 4.0 International License (license summary available at https://creativecommons.org/licenses/by/4.0/
- and complete license terms available at https://creativecommons.org/licenses/by/4.0/legalcode).
- */
- using Sansar.Simulation;
- /// <summary>
- /// teleport when someone (or some thing) enters the volume the script is attached to.
- /// </summary>
- public class trigvol_teleport : SceneObjectScript
- {
- public Sansar.Vector TP_Dest;
- public override void Init()
- {
- RigidBodyComponent rigidBody;
- // Collision events are related to the RigidBody component so we must find it.
- // See if this object has a RigidBodyComponent and grab the first one.
- if (ObjectPrivate.TryGetFirstComponent(out rigidBody)
- && rigidBody.IsTriggerVolume())
- {
- // Subscribe to TriggerVolume collisions on our rigid body: our callback (OnCollide) will get called
- // whenever a character or character vr hand or dynamic object collides with our trigger volume
- rigidBody.Subscribe(CollisionEventType.cTrigger, OnCollide);
- }
- else
- {
- // This will write to the script console
- Log.Write("Couldn't find rigid body, or rigid body is not a trigger volume!");
- }
- }
- // "Collision" events are really RigidBody events, and they get RigidBodyData.
- private void OnCollide(CollisionEventType EventType, Sansar.Script.ComponentId ComponentId, Sansar.Script.ComponentId HitComponentId, ObjectPublic HitObject, CollisionEventPhase phase, ControlPointType hitControlPoint)
- {
- if (hitControlPoint != ControlPointType.Invalid) return; // Ignore hands
- if (phase == CollisionEventPhase.cTriggerEnter)
- {
- //ScenePrivate.Chat.MessageAllUsers($"Object {HitComponentId.ObjectId} has entered my volume!");
- try
- {
- // Get a full API for the objet we hit, since we are a part of the scene.
- ObjectPrivate objectprivate = ScenePrivate.FindObject(HitObject.ObjectId);
- // AnimationComponents own the position of characters. To set a person's position we must do it through the animation component.
- AnimationComponent anim;
- if (objectprivate.TryGetFirstComponent(out anim))
- {
- // If there is an AnimationComponent use it to set the character's position.
- anim.SetPosition(TP_Dest);
- }
- }
- catch (System.Exception e)
- {
- // If the person is no longer in the scene then a null reference exception is thrown: just ignore it.
- if (!(e is System.NullReferenceException))
- {
- // Log other exceptions.
- Log.Write("Got exception trying to set agent position: " + e.ToString());
- }
- }
- }
- else
- {
- // HitObject might be null if the object or avatar is no longer in the scene, here we are just reporting the object id.
- //ScenePrivate.Chat.MessageAllUsers($"Object {HitComponentId.ObjectId} has left my volume!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement