add velocity_flow
This commit is contained in:
parent
f12f919c63
commit
1643b4e1a5
@ -63,6 +63,26 @@ function get(s)
|
|||||||
s.data.streamline
|
s.data.streamline
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function rotate_vector(x0, y0, theta)
|
||||||
|
local x1 = x0 * math.cos(theta) - y0 * math.sin(theta)
|
||||||
|
local y1 = x0 * math.sin(theta) + y0 * math.cos(theta)
|
||||||
|
return vm.vec2(x1, y1)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function velocity_flow(dt, force, mass, velocity, max_speed, min_speed)
|
||||||
|
if (mass == 0) then
|
||||||
|
mass = 1
|
||||||
|
end
|
||||||
|
local a = force * dt / mass
|
||||||
|
|
||||||
|
-- local theta_a = rotate_vector(force[1], 0, force[2])
|
||||||
|
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
|
||||||
|
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]
|
||||||
@ -83,14 +103,8 @@ 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)
|
||||||
|
|
||||||
if (mass == 0) then
|
|
||||||
mass = 1
|
|
||||||
end
|
|
||||||
local a = force * dt / mass
|
|
||||||
|
|
||||||
self.data.velocity = self.data.velocity + a
|
|
||||||
self.data.velocity[1] = vm.clamp(self.data.velocity[1], min_speed, max_speed)
|
|
||||||
-- 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 + self.data.velocity
|
||||||
-- end
|
-- end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user