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



Reply to topic  [ 6 posts ] 
 SetMagnitude trouble 
Author Message
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post SetMagnitude trouble
Once again, my Lua stuff gets errors for no apparent reason. I made a simple script to push stuff around with particles, and yet it doesn't work. I mean, at least not the way I wanted it to. Here's the thing:

Code:
function Create(self)
   self.timer = Timer();
   self.newmag = 0
end


function Update(self)

 
      for actor in MovableMan.Actors do
            local avgx = actor.Pos.X - self.Pos.X;
            local avgy = actor.Pos.Y - self.Pos.Y;
            local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
            if dist < 20 and self.timer:IsPastRealMS(10) then
               self.newmag = self.Vel.Magnitude + actor.Vel.Magnitude - (((actor.Pos.X - self.Pos.X) + (actor.Pos.Y - self.Pos.Y))/2) - (actor.Mass/2);
               actor.Vel = actor.Vel + self.Vel;
               print (self.newmag);
               actor.Vel:SetMagnitude(self.newmag);
            end
      end
end


So, basically, I wanted it to set the actor's vel magnitude based on several parameters, such as mass, previous vel, etc. The "print" line returns a number based on such parameters. And yet, the console doesn't accept that as a SetMagnitude command, and keeps returning "no overload of actor:setmagnitude matches parameters...". I fear that something weird and unbeknownst to me is happening there. Anyone knows why?


Sun Aug 16, 2009 4:55 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: SetMagnitude trouble
Make a local vector, then set magnitude on that, then set the actor's Vel to that local vector.

Basically, actor.Vel is a property which happens to be a vector; it's not a strict Vector class vector. So you duplicate it to a straight up vector vector and then use SetMagnitude on that.


Sun Aug 16, 2009 5:32 pm
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: SetMagnitude trouble
Egad, it works! Thanks a lot.

Yet, another problem has been found. When the particles hit stuff, it tends to go on the wrong direction, like this:
Image

And no, mutiplying the actor's vel by -1 doesn't solve the problem.


Sun Aug 16, 2009 10:28 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: SetMagnitude trouble
Well you're not accounting for hflipped, that's why. Vectors are absolute left to right, and obviously your code is returning positive X velocity. Try dividing (yeah, dividing) the vector by -1 if hflipped = true. (if you're facing right hflipped is false).

Also, is this being run on the actor or the gun?


Sun Aug 16, 2009 10:33 pm
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: SetMagnitude trouble
I don't think so. I'm dealing with MOParticles, and they don't even have a HFlipped variable. But I get your point, though. I'll try making the script check if actor.Pos.X - self.Pos.X is negative, and, if so, divide the actor's vel by -1.


Sun Aug 16, 2009 11:51 pm
Profile WWW
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: SetMagnitude trouble
Code:
local dist = (actor.Pos - self.Pos).Magnitude;
please..
also yeah, its the difference in X that you're having problems with.


Mon Aug 17, 2009 3:41 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 6 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.071s | 13 Queries | GZIP : Off ]