Data Realms Fan Forums
http://45.55.195.193/

Ballistic Crazyness!
http://45.55.195.193/viewtopic.php?f=73&t=15673
Page 1 of 1

Author:  zalo [ Wed Jul 01, 2009 10:29 pm ]
Post subject:  Ballistic Crazyness!

Code:
function Create(self)
   grav = SceneMan.GlobalAcc.Y;
   Vel = 25;
function lengthdir_x(dist,ang)
   return dist * math.cos(-ang);
end
function lengthdir_y(dist,ang)
   return dist * math.sin(-ang);
end
Holding = 0
curdist = 100
avgx = 0
avgy = 0
dist = 0
end
function Update(self)
   for actor in MovableMan.Actors do
      if actor:IsDead() == false then
         avgx = actor.Pos.X - self.Pos.X;
         avgy = actor.Pos.Y - self.Pos.Y;
         dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
         if dist < curdist then
            target = actor;
         end
      end
   end
   if (Vel^4 - grav * (grav * (target.Pos.X - self.Pos.X)^2 + 2 * (target.Pos.Y - self.Pos.Y)^2)) > 0 and (UInputMan:KeyHeld(8)) then
      local Angle = math.atan2(Vel^2 + math.sqrt(Vel^4 - grav * (grav * (target.Pos.X - self.Pos.X)) + 2 * (target.Pos.Y - self.Pos.Y)^2) / grav * (target.Pos.X - self.Pos.X));
      self:SetAimAngle(Angle);
   else
      print("TOO FAR AWAY");
   end
end


Now it spams the Too Far away message, even when an actor is within range.

It also says that on line 28 in the math.atan2 that it expected a number, but got nothing.

By the way, Image is line 28's equation.

Author:  mail2345 [ Wed Jul 01, 2009 10:31 pm ]
Post subject:  Re: Parentheses Madness!

Migrate some of that stuff to another line or a function.

Author:  piipu [ Wed Jul 01, 2009 10:50 pm ]
Post subject:  Re: Parentheses Madness!

Edit: Oops, miscounted them.
Editedit:My guess is this
Code:
if (Vel^4 - grav(grav*(
should be
Code:
if (Vel^4 - grav * (grav*(
Triple Edit: Fix the 2(stuff too from later on.

Author:  zalo [ Thu Jul 02, 2009 12:09 am ]
Post subject:  Re: Parentheses Madness!

'k, I got that part to work, thanks, but now it spams the "Too Far away" message.

Also, it says that On line 28 in the atan2 it expected a number, but got no value.

Updated first post.

Author:  piipu [ Thu Jul 02, 2009 12:28 am ]
Post subject:  Re: Ballistic Crazyness!

The spam happens because it will print it for every actor that's not within the range. I'll take a look at the math tomorrow, it's 2:30 am here.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/