View unanswered posts | View active topics It is currently Thu Dec 26, 2024 4:49 pm



Reply to topic  [ 5 posts ] 
 Ballistic Crazyness! 
Author Message

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post 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.


Wed Jul 01, 2009 10:29 pm
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Parentheses Madness!
Migrate some of that stuff to another line or a function.


Wed Jul 01, 2009 10:31 pm
Profile
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post 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.


Wed Jul 01, 2009 10:50 pm
Profile

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post 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.


Thu Jul 02, 2009 12:09 am
Profile WWW
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post 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.


Thu Jul 02, 2009 12:28 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.046s | 13 Queries | GZIP : Off ]