So when you left click; a beacon spawns, they are square and very small
When you right click; a spawner appears, spawners are circles
The lighters, which are the products of the spawners, will then go to the beacons.
However, if you place the beacons in a line like this;
The lighters will end up pausing in the middle.
Lighters pause in midpoints
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 15
- Joined: Sat Aug 19, 2017 9:13 am
Lighters pause in midpoints
- Attachments
-
- main.lua
- (4.09 KiB) Downloaded 205 times
Re: Lighters pause in midpoints
I've changed the indentation to make your file more readable. It seems the code you posted does not behave as you describe, you probably posted a different version.
I recommend you read a guide on how to properly format your code to be readable and maintainable. Here's a start http://lua-users.org/wiki/LuaStyleGuide
I recommend you read a guide on how to properly format your code to be readable and maintainable. Here's a start http://lua-users.org/wiki/LuaStyleGuide
- Attachments
-
- main.lua
- (3.86 KiB) Downloaded 164 times
-
- Prole
- Posts: 15
- Joined: Sat Aug 19, 2017 9:13 am
Re: Lighters pause in midpoints
It actually still does the pause in midpoints. I would like it to go from first beacon placed to second, then third.
Does anyone know how to do that?
Does anyone know how to do that?
- Attachments
-
- main.lua
- (3.86 KiB) Downloaded 173 times
Re: Lighters pause in midpoints
Sorry I missed the part where you needed to press the button "a" for the units to spawn. The reason your units stop in the middle of even number of spawners is because you're moving them once for each target, so when there's an equal amount of targets on each side their movements cancel out.HedgeHog builder wrote: ↑Thu Oct 19, 2017 7:01 am It actually still does the pause in midpoints. I would like it to go from first beacon placed to second, then third.
Does anyone know how to do that?
Here's a very crude example of how you could determine which target the units should go to next.
- Attachments
-
- main.lua
- (4.03 KiB) Downloaded 174 times
-
- Prole
- Posts: 15
- Joined: Sat Aug 19, 2017 9:13 am
Re: Lighters pause in midpoints
Code: Select all
for i,v in ipairs(Opposing_Pens) do
for k,Beacon in ipairs(Beacons) do
if (v.target == nil) then
v.target = k
elseif (v.target ~= k) then
break
end
For each index and value of opposing pens do;
for each index and value of beacons do;
if the target of opposing pens is non existent; then target is set to index of a beacon
else if the target is not k, then finish the loop
Correct?
Re: Lighters pause in midpoints
Yes. 'break' always ends only one loop, the one it is called from. The outer loop keeps going.HedgeHog builder wrote: ↑Fri Oct 20, 2017 7:33 amSo line by line:
For each index and value of opposing pens do;
for each index and value of beacons do;
if the target of opposing pens is non existent; then target is set to index of a beacon
else if the target is not k, then finish the loop
Correct?
The target is then removed once collision is detected and target is destroyed. If you want to be fancy you can determine the target by calculating the distance from the unit to all the targets and picking the one with the one with shortest distance.
-
- Prole
- Posts: 15
- Joined: Sat Aug 19, 2017 9:13 am
Re: Lighters pause in midpoints
So if I wanted to do comparison on distance between 2 points from the unit would I do
Code: Select all
unitdist 1 = unit.x - k.x
unit 2 = unit.x - k.x
if unitdist1 < unit2 then
target = unitdist1
else
target = unit2
Re: Lighters pause in midpoints
Distance between 2 points would beHedgeHog builder wrote: ↑Sun Oct 22, 2017 3:07 amSo if I wanted to do comparison on distance between 2 points from the unit would I do
Code: Select all
local distance = math.sqrt((unit.x-k.x)^2 + (unit.y-k.y)^2)
-
- Prole
- Posts: 15
- Joined: Sat Aug 19, 2017 9:13 am
Re: Lighters pause in midpoints
How would I select the closest one?
if distance < k.x,k.y?
if distance < k.x,k.y?
Re: Lighters pause in midpoints
Here is a tutorial for a minimum value algorithm: http://www.programming4beginners.com/tu ... -algorithm
You'll have to iterate through all potential targets and apply that to pick the one with the shortest distance.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests