steering_behaviors 1.0.7 → 2.0.0

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.
@@ -1,5 +1,14 @@
1
1
  # Changelog for steering-behaviors
2
2
 
3
+ ## 1.1.0, 13 August 2013
4
+ * Predictive interception lookahead tweaked slightly
5
+ * Bugfix: angle-limited steering could never be accelerative
6
+ * Evasion & pursuit demos are slower and more illustrative
7
+ * Separation demo includes danger-radius circle, smaller time lookahead
8
+ * Separation steering force scaled by speed for proper strength
9
+ * feel_the_force() returns immediately for zero-vector steering
10
+ * Bumping minor number; honestly, should have done this on 11 Aug
11
+
3
12
  ## 1.0.7, 12 August 2013
4
13
  * Fix embarrassing bug (left 'puts' statements uncommented in prior release)
5
14
 
@@ -4,7 +4,7 @@
4
4
  # This file is part of The Ruby Steering Behaviors Library.
5
5
  # http://github.com/cpowell/steering-behaviors
6
6
  # You can redistribute and/or modify this software only in accordance with
7
- # the terms found in the "LICENSE" file included with the framework.
7
+ # the terms found in the "LICENSE" file included with the library.
8
8
 
9
9
  class SteeringBehaviors::Align
10
10
 
@@ -4,7 +4,7 @@
4
4
  # This file is part of The Ruby Steering Behaviors Library.
5
5
  # http://github.com/cpowell/steering-behaviors
6
6
  # You can redistribute and/or modify this software only in accordance with
7
- # the terms found in the "LICENSE" file included with the framework.
7
+ # the terms found in the "LICENSE" file included with the library.
8
8
 
9
9
  class SteeringBehaviors::Arrive
10
10
  # Arrive 'gently' at the goal position by decelerating smoothly.
@@ -4,7 +4,7 @@
4
4
  # This file is part of The Ruby Steering Behaviors Library.
5
5
  # http://github.com/cpowell/steering-behaviors
6
6
  # You can redistribute and/or modify this software only in accordance with
7
- # the terms found in the "LICENSE" file included with the framework.
7
+ # the terms found in the "LICENSE" file included with the library.
8
8
 
9
9
  class SteeringBehaviors::Broadside
10
10
 
@@ -4,7 +4,7 @@
4
4
  # This file is part of The Ruby Steering Behaviors Library.
5
5
  # http://github.com/cpowell/steering-behaviors
6
6
  # You can redistribute and/or modify this software only in accordance with
7
- # the terms found in the "LICENSE" file included with the framework.
7
+ # the terms found in the "LICENSE" file included with the library.
8
8
 
9
9
  module SteeringBehaviors::Common
10
10
 
@@ -93,7 +93,7 @@ module SteeringBehaviors::Common
93
93
  tf = 1.8
94
94
  when 0
95
95
  gen="ahead, perpendicular"
96
- tf = 1.35
96
+ tf = 1.45
97
97
  when -1
98
98
  gen="ahead, anti-parallel"
99
99
  tf = 1.10
@@ -4,18 +4,18 @@
4
4
  # This file is part of The Ruby Steering Behaviors Library.
5
5
  # http://github.com/cpowell/steering-behaviors
6
6
  # You can redistribute and/or modify this software only in accordance with
7
- # the terms found in the "LICENSE" file included with the framework.
7
+ # the terms found in the "LICENSE" file included with the library.
8
8
 
9
9
  class SteeringBehaviors::Evade
10
10
  extend SteeringBehaviors::Common
11
11
 
12
- # Evade a moving target by anticipating its future position. Calculates where it thinks
13
- # the target will be, and leverages 'flee' to calculate how to best escape.
12
+ # Evade a moving target by anticipating its future position. Our character calculates
13
+ # where it thinks the enemy will be, and leverages 'flee' to calculate how to best escape.
14
14
  # See http://www.red3d.com/cwr/steer/
15
15
  #
16
16
  # * *Args* :
17
17
  # - +character_kinematic+ -> kinematic of "our" character that is moving and evading
18
- # - +other_kinematic+ -> kinematic of the thing to evade
18
+ # - +enemy_kinematic+ -> kinematic of the thing to evade
19
19
  # * *Returns* :
20
20
  # - a steering force
21
21
  #
@@ -4,7 +4,7 @@
4
4
  # This file is part of The Ruby Steering Behaviors Library.
5
5
  # http://github.com/cpowell/steering-behaviors
6
6
  # You can redistribute and/or modify this software only in accordance with
7
- # the terms found in the "LICENSE" file included with the framework.
7
+ # the terms found in the "LICENSE" file included with the library.
8
8
 
9
9
  class SteeringBehaviors::Flee
10
10
 
@@ -4,7 +4,7 @@
4
4
  # This file is part of The Ruby Steering Behaviors Library.
5
5
  # http://github.com/cpowell/steering-behaviors
6
6
  # You can redistribute and/or modify this software only in accordance with
7
- # the terms found in the "LICENSE" file included with the framework.
7
+ # the terms found in the "LICENSE" file included with the library.
8
8
 
9
9
  class SteeringBehaviors::Match
10
10
 
@@ -4,7 +4,7 @@
4
4
  # This file is part of The Ruby Steering Behaviors Library.
5
5
  # http://github.com/cpowell/steering-behaviors
6
6
  # You can redistribute and/or modify this software only in accordance with
7
- # the terms found in the "LICENSE" file included with the framework.
7
+ # the terms found in the "LICENSE" file included with the library.
8
8
 
9
9
  class SteeringBehaviors::Orthogonal
10
10
 
@@ -4,7 +4,7 @@
4
4
  # This file is part of The Ruby Steering Behaviors Library.
5
5
  # http://github.com/cpowell/steering-behaviors
6
6
  # You can redistribute and/or modify this software only in accordance with
7
- # the terms found in the "LICENSE" file included with the framework.
7
+ # the terms found in the "LICENSE" file included with the library.
8
8
 
9
9
  class SteeringBehaviors::Pursue
10
10
  extend SteeringBehaviors::Common
@@ -4,7 +4,7 @@
4
4
  # This file is part of The Ruby Steering Behaviors Library.
5
5
  # http://github.com/cpowell/steering-behaviors
6
6
  # You can redistribute and/or modify this software only in accordance with
7
- # the terms found in the "LICENSE" file included with the framework.
7
+ # the terms found in the "LICENSE" file included with the library.
8
8
 
9
9
  class SteeringBehaviors::Seek
10
10
 
@@ -4,7 +4,7 @@
4
4
  # This file is part of The Ruby Steering Behaviors Library.
5
5
  # http://github.com/cpowell/steering-behaviors
6
6
  # You can redistribute and/or modify this software only in accordance with
7
- # the terms found in the "LICENSE" file included with the framework.
7
+ # the terms found in the "LICENSE" file included with the library.
8
8
 
9
9
  class SteeringBehaviors::Separation
10
10
  extend SteeringBehaviors::Common
@@ -31,7 +31,7 @@ class SteeringBehaviors::Separation
31
31
  forwardness = unit_offset.dot(character_kinematic.heading_vec)
32
32
  parallelness = character_kinematic.heading_vec.dot(other_kinematic.heading_vec)
33
33
 
34
- side_vec = character_kinematic.heading_vec.perpendicular
34
+ side_vec = character_kinematic.heading_vec.perpendicular * character_kinematic.speed
35
35
 
36
36
  if parallelness < -0.707
37
37
  # anti-parallel, head-on paths; steer away from the threat's future pos
@@ -4,7 +4,7 @@
4
4
  # This file is part of The Ruby Steering Behaviors Library.
5
5
  # http://github.com/cpowell/steering-behaviors
6
6
  # You can redistribute and/or modify this software only in accordance with
7
- # the terms found in the "LICENSE" file included with the framework.
7
+ # the terms found in the "LICENSE" file included with the library.
8
8
 
9
9
  class SteeringBehaviors::Steering
10
10
 
@@ -12,24 +12,28 @@ class SteeringBehaviors::Steering
12
12
  # Takes turn rate limitations, mass, and other limits into account, and
13
13
  # directly alters the provided Mobile component.
14
14
  #
15
+ # The options hash lets you alter the behaviors a bit from the 'canonical'
16
+ # behaviors. The routine understands these settings:
17
+ # * permit_accel => (boolean) whether the steering force should be permitted to
18
+ # accelerate our agent; set it to false if that is undesirable.
19
+ # * permit_decel => (boolean) whether the steering force should be permitted to
20
+ # decelerate our agent; set it to false if that is undesirable.
15
21
  # * *Args* :
16
22
  # - +character_kinematic+ -> "our" character that is moving
17
23
  # - +steering_force+ -> force vector supplied by a steering behavior
18
24
  # - +delta+ -> time delta (in seconds) used for scaling the result
25
+ # - +options+ -> hash of user-set options for tuning the steering
19
26
  #
20
- def self.feel_the_force(character_kinematic, steering_force, delta, accelerative=true)
21
- return if steering_force.nil?
22
-
23
- acceleration = steering_force / character_kinematic.mass
27
+ def self.feel_the_force(character_kinematic, steering_force, delta, options={})
28
+ return if steering_force.nil? || steering_force == SteeringBehaviors::VEC_ZERO
24
29
 
25
30
  # Compute the new, proposed velocity vector.
31
+ acceleration = steering_force / character_kinematic.mass
26
32
  desired_velocity = character_kinematic.velocity_vec + (acceleration * delta)
27
- desired_velocity.truncate!(character_kinematic.speed) if !accelerative
28
- desired_velocity.truncate!(character_kinematic.max_speed)
29
33
 
30
34
  # If this timeslice's proposed velocity-vector exceeds the turn rate,
31
35
  # come up with a revised velociy-vec that doesn't exceed the rate -- and use that.
32
- angle = Math.acos character_kinematic.heading_vec.clamped_dot(desired_velocity.normalize)
36
+ angle = Math.acos character_kinematic.heading_vec.clamped_dot(desired_velocity.normalize)
33
37
  max_course_change = character_kinematic.max_turn * delta
34
38
 
35
39
  if angle.abs > max_course_change
@@ -44,13 +48,28 @@ class SteeringBehaviors::Steering
44
48
  # desired_velocity.radians,
45
49
  # limited_crse
46
50
 
47
- character_kinematic.velocity_vec = SteeringBehaviors::Vector.new(
48
- Math.sin(limited_crse) * character_kinematic.speed,
49
- Math.cos(limited_crse) * character_kinematic.speed
51
+ desired_velocity = SteeringBehaviors::Vector.new(
52
+ Math.sin(limited_crse) * desired_velocity.length,
53
+ Math.cos(limited_crse) * desired_velocity.length
50
54
  )
51
- else
52
- character_kinematic.velocity_vec = desired_velocity
53
55
  end
56
+
57
+ opts = {:permit_accel=>true, :permit_decel=>true}.merge(options)
58
+
59
+ # Don't permit acceleration if the caller disabled it
60
+ if !opts[:permit_accel]
61
+ desired_velocity.truncate!(character_kinematic.speed)
62
+ end
63
+
64
+ # Don't permit deceleration if the caller disabled it
65
+ if !opts[:permit_decel] && desired_velocity.length < character_kinematic.speed
66
+ desired_velocity = desired_velocity.normalize! * character_kinematic.speed
67
+ end
68
+
69
+ # And of course obey the character's maximum speed
70
+ desired_velocity.truncate!(character_kinematic.max_speed)
71
+
72
+ character_kinematic.velocity_vec = desired_velocity
54
73
  end
55
74
 
56
75
  end
@@ -4,7 +4,7 @@
4
4
  # This file is part of The Ruby Steering Behaviors Library.
5
5
  # http://github.com/cpowell/steering-behaviors
6
6
  # You can redistribute and/or modify this software only in accordance with
7
- # the terms found in the "LICENSE" file included with the framework.
7
+ # the terms found in the "LICENSE" file included with the library.
8
8
 
9
9
  class SteeringBehaviors::Vector
10
10
  TWOPI = 6.283185307179586
@@ -4,7 +4,7 @@
4
4
  # This file is part of The Ruby Steering Behaviors Library.
5
5
  # http://github.com/cpowell/steering-behaviors
6
6
  # You can redistribute and/or modify this software only in accordance with
7
- # the terms found in the "LICENSE" file included with the framework.
7
+ # the terms found in the "LICENSE" file included with the library.
8
8
 
9
9
  class SteeringBehaviors::Wander
10
10
 
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.7
5
+ version: 2.0.0
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-08-12 00:00:00.000000000 Z
12
+ date: 2013-08-13 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.