steering_behaviors 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog for steering-behaviors
2
2
 
3
+ ## 1.0.4, 8 August 2013
4
+ * Rewrote 'arrive' to the more canonical behavior described by Reynolds
5
+
3
6
  ## 1.0.3, 31 July 2013
4
7
  * Bugfixes in ortho/bside; cleanup of align/match
5
8
 
@@ -7,28 +7,31 @@
7
7
  # the terms found in the "LICENSE" file included with the framework.
8
8
 
9
9
  class SteeringBehaviors::Arrive
10
+ TARGET_RADIUS=0
10
11
 
11
12
  # Arrive 'gently' at the goal position by decelerating smoothly.
12
13
  #
13
14
  # * *Args* :
14
15
  # - +kinematic+ -> the thing that is moving and arriving
15
16
  # - +goal_position+ -> a Vector of position
16
- # - +gentleness+ -> higher values will make the arrival more gradual and 'gentle'
17
+ # - +slow_radius+ -> don't begin decelerating until inside this radius; max speed outside
17
18
  # * *Returns* :
18
19
  # - a steering force
19
20
  #
20
- def self.steer(kinematic, goal_position, gentleness=0.8)
21
+ def self.steer(kinematic, goal_position, slow_radius=200)
21
22
  to_target = goal_position - kinematic.position_vec
22
23
  dist = to_target.length
23
24
 
24
- if dist > 0
25
- desired_speed = dist / gentleness
26
- desired_speed = [desired_speed, kinematic.max_speed].min
27
-
28
- desired_velocity = to_target.normalize * desired_speed
29
- return desired_velocity - kinematic.velocity_vec
30
- else
25
+ if dist < TARGET_RADIUS
31
26
  return SteeringBehaviors::Vector.new(0,0)
27
+ elsif dist > slow_radius
28
+ desired_speed = kinematic.max_speed
29
+ else
30
+ desired_speed = kinematic.max_speed * dist / slow_radius
32
31
  end
32
+
33
+ desired_vel = to_target.normalize * desired_speed
34
+
35
+ return desired_vel - kinematic.velocity_vec
33
36
  end
34
37
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: steering_behaviors
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.3
5
+ version: 1.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Chris Powell
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-31 00:00:00.000000000 Z
12
+ date: 2013-08-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: |
15
15
  If you're building a game, you need your game agents and characters to move on their own. A standard way of doing this is with 'steering behaviors'. The seminal paper by Craig Reynolds established a core set of steering behaviors that could be utilized for a variety of common movement tasks and natural behaviors. This Ruby library can accomplish many/most of those tasks for your Ruby / JRuby game. The basic behaviors can be layered for more complicated and advanced behaviors, such as flocking and crowd movement.