diff options
author | the lemons <citrons@mondecitronne.com> | 2023-04-24 16:20:50 -0500 |
---|---|---|
committer | the lemons <citrons@mondecitronne.com> | 2023-04-24 16:20:50 -0500 |
commit | 2acdea651175368fdb133b13f635b3ac23f3e85d (patch) | |
tree | 0cad19f19762f5b10b7f049e982b6c99c0fb154a | |
parent | c7e8fc9a8b0db7b46785b6d14a5f2d0a7118a202 (diff) |
angular velocity relative to velocity
-rw-r--r-- | obj.lua | 5 | ||||
-rw-r--r-- | objects/x.lua | 2 |
2 files changed, 4 insertions, 3 deletions
@@ -203,7 +203,7 @@ function obj:energy() end function obj:observe_avel(o) - return o.data.avel - self.data.avel + return o.data.avel - util.magnitude(self.data.vel) end function obj:observe_vel(o) @@ -230,7 +230,8 @@ function obj:avel_to_accel(o, ax, ay) return false end local vx, vy = unpack(self.data.vel) - o.data.avel = self.data.avel + (math.sqrt(ave) * (avel >= 0 and 1 or -1)) + o.data.avel = + util.magnitude{vx, vy} + (math.sqrt(ave) * (avel >= 0 and 1 or -1)) o.data.vel = {vx + nvx, vy + nvy} return true end diff --git a/objects/x.lua b/objects/x.lua index f97d1d4..080887b 100644 --- a/objects/x.lua +++ b/objects/x.lua @@ -19,7 +19,7 @@ function x_obj:tick() local px, py = self:observe_pos(o) local mag = util.magnitude{px, py} local dx, dy = px / mag, py / mag - self:avel_to_accel(o, dx * mag/range, dy * mag/range) + self:avel_to_accel(o, dx * mag/range/10, dy * mag/range/10) end end end |