User Tools

Site Tools


dragengine:modules:dragonscript:behavior_grabspot

ECBehaviorGrabSpot

Behavior adding support to define grab spot for actors.

Defines position and orientation where the actor can grab the owner element. 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 an actor is grabbing the grab spot. Hence at most one actor can grab an grab spot at each time.

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

Instance Counts

This behavior can be used multiple times on an element to add different grab spots. Use the behavior identifier to tell them apart.

Element Class Properties

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

touchCollider.physicsType

Physics type of touch collider used to detect touching grabbers.

  • Full name: grabSpot.touchCollider.physicsType or grabSpot(id).touchCollider.physicsType
  • Type: enumeration
  • Allowed Values:

    ValueDescription
    noneCollider is not moving and will not move by collisions.
    dynamicCollider reacts to impacts using physical simulation.
    kinematicGame scripts define the collision response.
  • Default Value: kinematic
  • Example (*.deeclass):
    <string name='grabSpotright).touchCollider.physicsType>kinematic</string>

touchCollider.localGravity

Local gravity of touch collider if not affected by world gravity.

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

touchCollider.weight

Weight (mass) of touch collider if dynamic.

  • Full name: grabber.touchCollider.weight or grabber(id).touchCollider.weight
  • Type: float
  • Default Value: 1
  • Example (*.deeclass):
    <float name='grabSpot(right).touchCollider.weight'>0.2</float>

touchCollider.enabled

Initial enabled state of touch collider.

  • Full name: grabber.touchCollider.enabled or grabber(id).touchCollider.enabled
  • Type: boolean
  • Default Value: true
  • Example (*.deeclass):
    <boolean name='grabSpot(right).touchCollider.enabled'>true</float>

touchCollider.shape

Shape of touch collider used to detect grabbers.

  • Full name: grabSpot.touchCollider.shape or grabSpot(id).touchCollider.shape
  • Type: string (shape format). See “Shape List Encoding” in CodecPropertyString.
  • Default Value: empty string
  • Example (*.deeclass):
    <string name='grabber(right).touchCollider.shape'>box:extends,0.1,0.1,0.1</string>

touchCollider.rig

Rig resource to use for touch collider.

  • Full name: grabSpot.touchCollider.rig or grabSpot(id).touchCollider.rig
  • Type: string
  • File Pattern: *.derig (all rig modules)
  • Default Value: empty path
  • Example (*.deeclass):
    <string name='grabSpot(right).touchCollider.rig'>grab_spot.derig</string>

position

Touch collider attach position relative to parent element or bone.

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

rotation

Touch collider attach orientation in euler degrees relative to parent element or bone.

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

bone

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

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

Events

spotGrabbed

Grabber has grabbed spot.

spotReleased

Grabber has release spot.

enabledChanged

Grab spot enabled changed.

Required Behaviors

This behavior does not required other behaviors to be present.

Optional Behaviors

Persistency

This behavior does support element class to be persistable (setPersistable).

API Documentation

ECBehaviorGrabSpot.

Since DragonScript Module Version 1.9

Use Cases

  • Allow player to grab objects in VR with his hands.
  • Add different grab spots on an object in VR to alter the interactions the player can do.

Element Class Example

class ExampleElementClass extends BehaviorElementClass
   public var ECBehaviorComponent component
   public var ECBehaviorCollider collider
   public var ECBehaviorGrabSpot grabSpot
   
   public func new() super("ExampleElement")
      // Create component and collider to give element a look and feeling
      component = ECBehaviorComponent.new(this)
      collider = ECBehaviorCollider.new(this, component)
      
      // Create grab spot 10cm along Z axis
      grabSpot = ECBehaviorGrabSpot.new(this, collider)
      grabSpot.getAttachTouchCollider().getPosition().setVector(Vector.new(0, 0, 0.1))
   end
end

Behavior Factory

Using element class supporting adding behaviors the behavior can be added like this:

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorComponent'/>
  <behavior type='ECBehaviorCollider'/>
 
  <behavior type='ECBehaviorGrabSpot'>
    <!-- optional: set collision filter. default value '4:1' which means
                   category BaseGameApp.CollisionFilterBit.trigger
                   filter BaseGameApp.CollisionFilterBit.dynamic.
                   format is '', 'category' or 'category:filter' where category and filter
                   are a list of bits to set. -->
    <string name='collisionFilter'>4:1 2</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.name'>Color 1</string>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorGrabSpot' id='second'/>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_grabspot.txt · Last modified: 2025/03/13 17:13 by dragonlord