steering_behaviors 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/lib/steering_behaviors/arrive.rb +12 -9
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -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
|
-
# - +
|
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,
|
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
|
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.
|
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-
|
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.
|