kinda work movement
This commit is contained in:
parent
ca11966ff4
commit
03c0f489b8
@ -14,7 +14,11 @@ end
|
|||||||
|
|
||||||
local default = {
|
local default = {
|
||||||
pos = vm.vec2(44.64, 10.87),
|
pos = vm.vec2(44.64, 10.87),
|
||||||
|
|
||||||
orientation = vm.vec2(0.0, 0.0),
|
orientation = vm.vec2(0.0, 0.0),
|
||||||
|
orientation_speed = vm.vec2(0.0, 0.0),
|
||||||
|
min_orientation_speed = -1.0,
|
||||||
|
max_orientation_speed = 1.0,
|
||||||
|
|
||||||
velocity = vm.vec2(0.0, 0.0),
|
velocity = vm.vec2(0.0, 0.0),
|
||||||
max_speed = 1.0,
|
max_speed = 1.0,
|
||||||
@ -69,20 +73,28 @@ local function rotate_vector(x0, y0, theta)
|
|||||||
return vm.vec2(x1, y1)
|
return vm.vec2(x1, y1)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function velocity_flow(dt, force, mass, velocity, max_speed, min_speed)
|
local function forward_velocity(dt, force, mass, velocity, max_speed, min_speed)
|
||||||
if (mass == 0) then
|
if (mass == 0) then
|
||||||
mass = 1
|
mass = 1
|
||||||
end
|
end
|
||||||
local a = force * dt / mass
|
local a = force[1] * dt / mass
|
||||||
|
local new_velocity = velocity[1] + a
|
||||||
-- local theta_a = rotate_vector(force[1], 0, force[2])
|
new_velocity = vm.clamp(new_velocity, min_speed, max_speed)
|
||||||
local new_velocity = velocity + a
|
|
||||||
new_velocity[1] = vm.clamp(new_velocity[1], min_speed, max_speed)
|
|
||||||
new_velocity[2] = vm.clamp(new_velocity[2], min_speed, max_speed)
|
|
||||||
|
|
||||||
return new_velocity
|
return new_velocity
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function orientation_velocity(dt, force, mass, orientation_speed, orientation, max_orientation, min_orientation)
|
||||||
|
if (mass == 0) then
|
||||||
|
mass = 1
|
||||||
|
end
|
||||||
|
local a = force[2] * dt / mass
|
||||||
|
local new_speed = orientation_speed + a
|
||||||
|
new_speed = vm.clamp(new_speed, min_orientation, max_orientation)
|
||||||
|
local new_orientation = rotate_vector(orientation[1], orientation[2], new_speed)
|
||||||
|
return new_orientation, new_speed
|
||||||
|
end
|
||||||
|
|
||||||
function world:update_race(dt)
|
function world:update_race(dt)
|
||||||
local x, y = self.data.pos[1], self.data.pos[2]
|
local x, y = self.data.pos[1], self.data.pos[2]
|
||||||
local or_x, or_y = self.data.orientation[1], self.data.orientation[2]
|
local or_x, or_y = self.data.orientation[1], self.data.orientation[2]
|
||||||
@ -103,10 +115,14 @@ function world:update_race(dt)
|
|||||||
magic_w.drag_boost, magic_w.drag_halt,
|
magic_w.drag_boost, magic_w.drag_halt,
|
||||||
magic_w.inertia, magic_w.centrifugal
|
magic_w.inertia, magic_w.centrifugal
|
||||||
)
|
)
|
||||||
self.data.velocity = velocity_flow(dt, force, mass, velocity, max_speed, min_speed)
|
local f_v = forward_velocity(dt, force, mass, velocity, max_speed, min_speed)
|
||||||
|
local o, o_v = orientation_velocity(dt, force, mass, self.data.orientation_speed, self.data.orientation, self.data.max_orientation_speed, self.data.min_orientation_speed)
|
||||||
|
|
||||||
|
self.data.velocity[1] = f_v
|
||||||
|
self.data.orientation_speed = o_v
|
||||||
|
self.data.orientation = o
|
||||||
-- if (self.data.velocity[1] ~= 0) then
|
-- if (self.data.velocity[1] ~= 0) then
|
||||||
self.data.pos = self.data.pos + self.data.velocity
|
self.data.pos = self.data.pos + o * f_v
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
self.data.inertia = force
|
self.data.inertia = force
|
||||||
@ -119,7 +135,7 @@ end
|
|||||||
function world:draw()
|
function world:draw()
|
||||||
local x, y = self.data.pos[1], self.data.pos[2]
|
local x, y = self.data.pos[1], self.data.pos[2]
|
||||||
local or_x, or_y = self.data.orientation[1], self.data.orientation[2]
|
local or_x, or_y = self.data.orientation[1], self.data.orientation[2]
|
||||||
local vx, vy = self.data.velocity[1], self.data.velocity[2]
|
local vx, vy = self.data.orientation[1] * self.data.velocity[1], self.data.orientation[2] * self.data.velocity[1]
|
||||||
|
|
||||||
test.set_sphere(x, y, vx, vy)
|
test.set_sphere(x, y, vx, vy)
|
||||||
end
|
end
|
||||||
@ -144,7 +160,7 @@ function world:ui_draw()
|
|||||||
debug_data(650, 0, 1.0, 0.0, 1.0, self.data)
|
debug_data(650, 0, 1.0, 0.0, 1.0, self.data)
|
||||||
debug_data(650, 400, 1.0, 0.0, 1.0, magic_w)
|
debug_data(650, 400, 1.0, 0.0, 1.0, magic_w)
|
||||||
|
|
||||||
local vx, vy = self.data.velocity[1], self.data.velocity[2]
|
local vx, vy = self.data.orientation[1], self.data.orientation[2]
|
||||||
debug_vector(vx, vy)
|
debug_vector(vx, vy)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,11 @@ local entities_default = {
|
|||||||
data = {
|
data = {
|
||||||
racer = {
|
racer = {
|
||||||
pos = vm.vec2(44.64, 10.87),
|
pos = vm.vec2(44.64, 10.87),
|
||||||
orientation = vm.vec2(0.0, 0.0),
|
|
||||||
|
orientation = vm.vec2(1.0, 0.0),
|
||||||
|
orientation_speed = 0.0,
|
||||||
|
min_orientation_speed = -1.0,
|
||||||
|
max_orientation_speed = 1.0,
|
||||||
|
|
||||||
velocity = vm.vec2(0.0, 0.0),
|
velocity = vm.vec2(0.0, 0.0),
|
||||||
max_speed = 1.0,
|
max_speed = 1.0,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user