PhysicsManager now has a job, CollisionManager enabled, using Player velocity instead of position for movement controls, added Entity drag, added spaces

This commit is contained in:
2019-08-09 08:27:34 -05:00
parent 3b662090fc
commit f84b680de5
5 changed files with 61 additions and 42 deletions

View File

@@ -14,7 +14,6 @@ class IMICFPS
@running_speed = 6.8 # meter's per second
@old_speed = @speed
@mass = 72 # kg
@floor = 0
@first_person_view = true
@devisor = 500.0
@@ -37,8 +36,8 @@ class IMICFPS
end
def draw_nameplate
_height = (@name_image.height/@devisor)
_width = (@name_image.width/@devisor)/2
_width = (@name_image.width / @devisor) / 2
_height = (@name_image.height / @devisor)
_y = 2#normalize_bounding_box(model.bounding_box).max_y+0.05
glPushMatrix
glRotatef(180, 0, 1, 0)
@@ -90,74 +89,74 @@ class IMICFPS
def update
relative_speed = @speed
if InputMapper.down?(:sprint)
relative_speed = (@running_speed)*(delta_time)
relative_speed = (@running_speed) * (delta_time)
else
relative_speed = @speed*(delta_time)
relative_speed = @speed * (delta_time)
end
relative_y_rotation = @rotation.y*-1
relative_y_rotation = @rotation.y * -1
if InputMapper.down?(:forward)
@position.z+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
@position.x-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
@velocity.z += Math.cos(relative_y_rotation * Math::PI / 180) * relative_speed
@velocity.x -= Math.sin(relative_y_rotation * Math::PI / 180) * relative_speed
end
if InputMapper.down?(:backward)
@position.z-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
@position.x+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
@velocity.z -= Math.cos(relative_y_rotation * Math::PI / 180) * relative_speed
@velocity.x += Math.sin(relative_y_rotation * Math::PI / 180) * relative_speed
end
if InputMapper.down?(:strife_left)
@position.z+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
@position.x+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
@velocity.z += Math.sin(relative_y_rotation * Math::PI / 180) * relative_speed
@velocity.x += Math.cos(relative_y_rotation * Math::PI / 180) * relative_speed
end
if InputMapper.down?(:strife_right)
@position.z-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
@position.x-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
@velocity.z -= Math.sin(relative_y_rotation * Math::PI / 180) * relative_speed
@velocity.x -= Math.cos(relative_y_rotation * Math::PI / 180) * relative_speed
end
if InputMapper.down?(:turn_left)
@rotation.y+=(relative_speed*1000)*delta_time
@rotation.y += (relative_speed * 1000) * delta_time
end
if InputMapper.down?(:turn_right)
@rotation.y-=(relative_speed*1000)*delta_time
@rotation.y -= (relative_speed * 1000) * delta_time
end
if @_time_in_air
air_time = ((Gosu.milliseconds-@_time_in_air)/1000.0)
@velocity.y-=(IMICFPS::GRAVITY*air_time)*delta_time
air_time = (Gosu.milliseconds - @_time_in_air) / 1000.0
@velocity.y -= IMICFPS::GRAVITY * air_time * delta_time
end
if InputMapper.down?(:jump) && !@jumping
@jumping = true
@_time_in_air = Gosu.milliseconds
elsif !@jumping && @position.y > @floor
elsif !@jumping
@falling = true
@_time_in_air ||= Gosu.milliseconds # FIXME
else
if @jumping
if @position.y <= @floor
@falling = false; @jumping = false; @velocity.y = 0; @position.y = @floor
end
if @jumping && @velocity.y <= 0
@falling = false
@jumping = false
end
end
if @jumping && !@falling
if InputMapper.down?(:jump)
@velocity.y = 1.5
@velocity.y += 1.5
@falling = true
end
end
@position.y+=@velocity.y*delta_time if @position.y >= @floor # TEMP fix to prevent falling forever, collision/physics managers should fix this in time.
super
end
def button_up(id)
def button_down(id)
if InputMapper.is?(:toggle_first_person_view, id)
@first_person_view = !@first_person_view
@visible = !@first_person_view
puts "First Person? #{@first_person_view}"
elsif InputMapper.is?(:turn_180, id)
@rotation.y = @rotation.y+180
@rotation.y = @rotation.y + 180
@rotation.y %= 360
end
end