User Tools

Site Tools


dragengine:modules:dragonscript:behavior_grabber

ECBehaviorGrabber

Behavior adding support to grab an ECBehaviorGrabSpot.

Grab spots are typically used for physics interaction like VR hand use but can be used also with mouse interaction. The actual grabbing interaction, exact grab location and orientation as well as attaching logic is handled by other behaviors using listening. This behavior also tracks if what grab spot an actor is grabbing. Hence at most one grab spot can be grabbed by this behavior at each time.

Elements able to be grabbed have to use the ECBehaviorGrabSpot behavior. Both the grab spot and the grabber have to persist the other behavior. During restoring no notifications are triggered this way.

To detect grab spots a touch sensor is added with a default sphere shape. By default the touch sensor is disabled and has to be enabled if the game logic allows grabbing. The collision filter category is set to BaseGameApp.CollisionFilterBit.trigger and the collision filter mask is set to BaseGameApp.CollisionFilterBit.dynamic.

Instance Counts

This behavior can be added multiple times to an element. Use the behavior identifier to tell them apart.

Element Class Properties

Element class properties have the prefix grabber. or grabber(id). if id is not empty.

shape

Shape of collider used to detect grab spots.

  • Full name: “grabber.shape” or “grabber(id).shape”
  • Type: string (shape list encoding)
  • Default Value: empty string
  • Example (*.deeclass):
    <string name='grabber(right).shape'>box:extends,0.1,0.1,0.1</string>

attach.position

Attach position relative to parent element or bone.

  • Full name: “grabber.attach.position” or “grabber(id).attach.position”
  • Type: 3-component vector
  • Default Value: (0, 0, 0)
  • Example (*.deeclass):
    <vector name='grabber(right).attach.position' x='0' y='0' z='0.1'/>

attach.rotation

Attach orientation in euler degrees relative to parent element or bone.

  • Full name: “grabber.attach.rotation” or “grabber(id).attach.rotation”
  • Type: 3-component vector
  • Default Value: (0, 0, 0)
  • Example (*.deeclass):
    <vector name='grabber(right).attach.rotation' x='-45' y='0' z='0'/>

attach.bone

Name of bone to attach to or empty string to attach to the parent element.

  • Full name: “grabber.attach.bone” or “grabber(id).attach.bone”
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass):
    <string name='grabber(right).attach.bone'>attach hand.r</string>

Required Behaviors

This behavior does require other behaviors.

Optional Behaviors

Persistency

Saves these parameters:

API Documentation

ECBehaviorGrabber.

Since DragonScript Module Version 1.9

Use Cases

  • Grab objects in VR

Element Class Example

The following example creates an element class with support to test what element the player is pointing at:

class MyElement extends BehaviorElementClass
   public var ECBehaviorVRPlayspace vrPlayspace
   public var ECBehaviorVRHand vrHandRight
   public var ECBehaviorVRHand vrHandLeft
   public var ECBehaviorGrabber vrRightHandGrabber
   public var ECBehaviorGrabber vrLeftHandGrabber
   
   public func new()
      // Create playspace
      vrPlayspace = ECBehaviorVRPlayspace.new(this)
      
      // Create hand controllers. The InputDeviceType indicates what device type
      // to monitor. vrRightHand and vrLeftHand can exist only once
      vrHandRight = ECBehaviorVRHand.new(this, vrPlayspace, InputDeviceType.vrRightHand, "right")
      vrHandLeft = ECBehaviorVRHand.new(this, vrPlayspace, InputDeviceType.vrLeftHand, "left")
      
      // Create grabbers for each hand
      vrRightHandGrabber = ECBehaviorGrabber.new(this, vrRightHand, "right")
      vrLeftHandGrabber = ECBehaviorGrabber.new(this, vrLeftHand, "left")
  end
end

The BaseVRActorClass provides full VR support including ECBehaviorGrabber for both hands.

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_grabber.txt · Last modified: 2024/03/14 16:51 by dragonlord