Class: Zyps::PullAction

Inherits:
TimedAction show all
Defined in:
lib/zyps/actions.rb

Overview

Pulls target toward actor.

Instance Attribute Summary collapse

Attributes inherited from TimedAction

#clock

Attributes inherited from Action

#started

Instance Method Summary collapse

Methods inherited from TimedAction

#copy, #delta, #initialize, #start, #stop

Methods inherited from Action

#copy, #initialize, #start, #started?, #stop

Constructor Details

This class inherits a constructor from Zyps::TimedAction

Instance Attribute Details

#rateObject

Units/second to accelerate target by.



212
213
214
# File 'lib/zyps/actions.rb', line 212

def rate
  @rate
end

Instance Method Details

#do(actor, targets) ⇒ Object

Pull the targets toward the actor, with force limited by elapsed time.



214
215
216
217
218
219
220
221
222
223
# File 'lib/zyps/actions.rb', line 214

def do(actor, targets)
	#Acceleration will be limited by elapsed time.
	pull_force = delta
	targets.each do |target|
		#Angle from target to actor is also angle of pull force (opposite of that for push).
		pull_angle = Utility.find_angle(target.location, actor.location)
		#Apply the force to the creature's movement vector.
		target.vector += Vector.new(pull_force, pull_angle)
	end
end