add velocity_flow
This commit is contained in:
parent
6bba132f3e
commit
ca11966ff4
@ -63,6 +63,26 @@ function get(s)
|
||||
s.data.streamline
|
||||
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)
|
||||
local x, y = self.data.pos[1], self.data.pos[2]
|
||||
local or_x, or_y = self.data.orientation[1], self.data.orientation[2]
|
||||
@ -83,16 +103,10 @@ function world:update_race(dt)
|
||||
magic_w.drag_boost, magic_w.drag_halt,
|
||||
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
|
||||
self.data.pos = self.data.pos + self.data.velocity
|
||||
self.data.pos = self.data.pos + self.data.velocity
|
||||
-- end
|
||||
|
||||
self.data.inertia = force
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user