Data Realms Fan Forums http://45.55.195.193/ |
|
SetMagnitude trouble http://45.55.195.193/viewtopic.php?f=73&t=16245 |
Page 1 of 1 |
Author: | Areku [ Sun Aug 16, 2009 4:55 pm ] |
Post subject: | 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? |
Author: | Grif [ Sun Aug 16, 2009 5:32 pm ] |
Post subject: | 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. |
Author: | Areku [ Sun Aug 16, 2009 10:28 pm ] |
Post subject: | 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: ![]() And no, mutiplying the actor's vel by -1 doesn't solve the problem. |
Author: | Grif [ Sun Aug 16, 2009 10:33 pm ] |
Post subject: | 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? |
Author: | Areku [ Sun Aug 16, 2009 11:51 pm ] |
Post subject: | 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. |
Author: | Geti [ Mon Aug 17, 2009 3:41 am ] |
Post subject: | Re: SetMagnitude trouble |
Code: local dist = (actor.Pos - self.Pos).Magnitude; also yeah, its the difference in X that you're having problems with. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |