User Tools

Site Tools


dragengine:modules:dragonscript:behavior_actorik

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revisionBoth sides next revision
dragengine:modules:dragonscript:behavior_actorik [2020/06/01 11:28] – created dragonlorddragengine:modules:dragonscript:behavior_actorik [2020/06/01 11:35] – [Element Class Example] dragonlord
Line 78: Line 78:
  
 <code> <code>
-// example class applying IK to one body group+pin Dragengine.Scenery 
 class ObjectElementClass extends BaseActorClass class ObjectElementClass extends BaseActorClass
    public var ECBehaviorActorIK actorIK    public var ECBehaviorActorIK actorIK
Line 94: Line 95:
 end end
  
-// example class applying IK to two body groups at the same time if desired +class ActorActionIK extends BAAFirstPerson 
-class ObjectElement2Class extends BaseActorClass+   public var ECBehaviorActorIK.Instance actorIK 
 +    
 +   public func new() 
 +   end 
 +    
 +   // store the behavior so we can use it 
 +   protected func void initBehaviors() 
 +      super.initBehaviors() 
 +      actorIK = ECBehaviorActorIK.getInstanceIn(actor) 
 +   end 
 +    
 +   // enable IK while this action is assigned to an actor then disable it again. 
 +   // using disable() instead of setEnabled(false) also clears the target 
 +   public func void activate() 
 +      super.activate() 
 +      actorIK.setTarget(targetElementToTouch) 
 +      actorIK.setEnabled(true) 
 +   end 
 +    
 +   public func void deactivate() 
 +      actorIK.disable() 
 +      super.deactivate() 
 +   end 
 +end 
 +</code> 
 + 
 +Example class applying IK to two body groups at the same time if desired
 +<code> 
 +pin Dragengine.Scenery 
 + 
 +class ObjectElementClass extends BaseActorClass
    public var ECBehaviorActorIK actorIKLeft    public var ECBehaviorActorIK actorIKLeft
    public var ECBehaviorActorIK actorIKRight    public var ECBehaviorActorIK actorIKRight
Line 116: Line 147:
      // using this setup actor actions can enable IK handling for each hand      // using this setup actor actions can enable IK handling for each hand
      // individually or for both at the same time      // individually or for both at the same time
 +   end
 +end
 +
 +class ActorActionIK extends BAAFirstPerson
 +   public var ECBehaviorActorIK.Instance actorIKLeft
 +   public var ECBehaviorActorIK.Instance actorIKRight
 +   
 +   public func new()
 +   end
 +   
 +   // store the behavior so we can use it
 +   protected func void initBehaviors()
 +      super.initBehaviors()
 +      actorIKLeft = ECBehaviorActorIK.getInstanceIn(actor, "left")
 +      actorIKRight = ECBehaviorActorIK.getInstanceIn(actor, "right")
 +   end
 +   
 +   // enable IK while this action is assigned to an actor then disable it again.
 +   // using disable() instead of setEnabled(false) also clears the target.
 +   // the element is facing us hence our left side is actually on the right side
 +   // from the point of view of the element. the target position is always
 +   // relative to the target element.
 +   public func void activate()
 +      super.activate()
 +      
 +      actorIKLeft.setTarget(targetElementToTouch, Vector.new(0.2, 0, 0))
 +      actorIKLeft.setEnabled(true)
 +      
 +      actorIKRight.setTarget(targetElementToTouch, Vector.new(-0.2, 0, 0))
 +      actorIKRight.setEnabled(true)
 +   end
 +   
 +   public func void deactivate()
 +      actorIKLeft.disable()
 +      actorIKRight.disable()
 +      super.deactivate()
    end    end
 end end
 </code> </code>
dragengine/modules/dragonscript/behavior_actorik.txt · Last modified: 2024/03/14 16:54 by dragonlord