games/example/lib/npc_movement.rb in game_machine-0.0.9 vs games/example/lib/npc_movement.rb in game_machine-0.0.10
- old
+ new
@@ -33,11 +33,11 @@
return
end
# Only update position if we moved
if position_changed
- commands.grid.track(id,position.x,position.y,0)
+ commands.grid.track(id,position.x,position.y,position.z)
@position_changed = false
end
@updates_for_move += 1
end
@@ -88,28 +88,22 @@
delta_time = Time.now.to_f - last_move.to_f
# Save object creation by not using methods that return new vector
x = current_target.x - position.x
y = current_target.y - position.y
- dirx = GameMachine::Vector.norm(x)
- diry = GameMachine::Vector.norm(y)
+ dirx,diry = GameMachine::Vector.norm(x,y)
position.x += dirx * speed_scale * delta_time
position.y += diry * speed_scale * delta_time
- #direction = (current_target - position).normalize
- #position.x += direction.x * speed_scale * delta_time
- #position.y += direction.y * speed_scale * delta_time
+ #dir = (current_target - position).normalize
+ #position.x += dir.x * speed_scale * delta_time
+ #position.y += dir.y * speed_scale * delta_time
- # Not really what we want
- #position.interpolate(current_target, speed_scale * delta_time)
if position.distance(current_target) > current_distance_to_target
set_reached_target
end
- #if id.match(/viking_499/) || id.match(/worm/)
- # puts "#{id}: old_distance :#{current_distance_to_target} new_distance: #{position.distance(current_target)} time: #{delta_time}"
- #end
@last_move = Time.now.to_f
@position_changed = true
end
end
end