Code: Select all
function inv_sqr_distance(x1, y1, x2, y2)
return 1/((x2-x1)^2 + (y2-y1)^2)
end
Code: Select all
function inv_sqr_distance(x1, y1, x2, y2)
return 1/((x2-x1)^2 + (y2-y1)^2)
end
Thanks for the correction!(Funny thing is that I had the function distance already so I was just gonna type 1/distance(...) ).pgimeno wrote: ↑Thu Feb 25, 2021 2:43 am The inverse square of the distance is actually 1/d², it's NOT the square root. Since calculating the distance involves a square root, that square root cancels with the square. The result is:
Code: Select all
function inv_sqr_distance(x1, y1, x2, y2) return 1/((x2-x1)^2 + (y2-y1)^2) end
Code: Select all
function boids:update(dt)
local dx, dy=math.cos(self.angle), math.sine(self.angle)
self.x = self.x+dx*self.vx*self.de*dt
self.y = self.y+dy*self.vy*self.de*dt
...
--defaults to one
self.de = 1
for _,i in ipairs(obstacles) do
--i={x,y,w=10,h=10}
local dist = unsquaredDistance(i,self)
local sdist = math.sqrt(dist)
local de = 1/dist
--??check if close or else they all keep still??--
if sdist<i.w then self.de=self.de*de end
end
end
Code: Select all
function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end
Code: Select all
Lua Error: [file Gunroar.lua]:18: C stack overflow
No, you see , the piece of code posted there makes sense to me, I even managed to adjust it to do what it needed to do,(thnx to that Xii's helpful comment) , and I just decided to post my implementation,togFox wrote: ↑Thu Feb 25, 2021 10:17 am What Xii has detailed (very well I have to say) is largely vector maths. It sounds scary but it's far easier to understand than calculus, algebra and even basic physics. I reckon if you spent one afternoon doing a medium dive into vectors and vector maths that script would make sense to you.
Code: Select all
function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end
Code: Select all
Lua Error: [file Gunroar.lua]:18: C stack overflow
At face value: none.Gunroar:Cannon() wrote: ↑Thu Feb 25, 2021 4:33 am 3)What's the difference in 1/dist and 1/distrootsqred?
Code: Select all
dist = math.sqrt((x2 - x1)^2 + (y2 - y1)^2)
Code: Select all
dist_squared = dist^2
-- expanding using the above formula we get:
dist_squared = math.sqrt((x2 - x1)^2 + (y2 - y1)^2)^2
-- and cancelling the sq.root with the squared:
dist_squared = (x2 - x1)^2 + (y2 - y1)^2
I was looking at the sqrt in distance() and wondering if I made a mistake. Thanks for correcting!pgimeno wrote: ↑Thu Feb 25, 2021 2:43 am The inverse square of the distance is actually 1/d², it's NOT the square root. Since calculating the distance involves a square root, that square root cancels with the square. The result is:
Code: Select all
function inv_sqr_distance(x1, y1, x2, y2) return 1/((x2-x1)^2 + (y2-y1)^2) end
pgimeno wrote: ↑Thu Feb 25, 2021 2:43 am The inverse square of the distance is actually 1/d², it's NOT the square root. Since calculating the distance involves a square root, that square root cancels with the square. The result is:
Code: Select all
function inv_sqr_distance(x1, y1, x2, y2) return 1/((x2-x1)^2 + (y2-y1)^2) end
That clears that up !
Hmmm, so, in essence, increasing the speed the bigger , nice, I'll try it.togFox wrote: ↑Thu Feb 25, 2021 1:14 pm If the size of the object is a factor and you want to 'flee' larger predators then after you determine your avoidance speed/velocity you can * by the size of the predator.
Small predators will reduce the delta velocity. Large predators will increase the delta velocity.
Code: Select all
function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end
Code: Select all
Lua Error: [file Gunroar.lua]:18: C stack overflow
I don't really know how to do that , but I think you're talking about including the obstacles in the grid so that A* will take it as a no-go area...
Code: Select all
function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end
Code: Select all
Lua Error: [file Gunroar.lua]:18: C stack overflow
Users browsing this forum: No registered users and 5 guests