Data Realms Fan Forums
http://forums.datarealms.com/

MOPixel won't stay put?
http://forums.datarealms.com/viewtopic.php?f=73&t=25507
Page 1 of 1

Author:  Awesomeness [ Wed Sep 14, 2011 1:39 am ]
Post subject:  MOPixel won't stay put?

How come this script doesn't work? :-(

Code:
function Create(self)
   self.StartPos = self.Pos;
   self.StartVel = self.Vel;
end
function Update(self)
   self.Pos = self.StartPos;
   self.Vel = self.StartVel;
end

Author:  Asklar [ Wed Sep 14, 2011 1:52 am ]
Post subject:  Re: MOPixel won't stay put?

And if you pin the MOPixel and give it a speed with lua?

Author:  Awesomeness [ Wed Sep 14, 2011 1:54 am ]
Post subject:  Re: MOPixel won't stay put?

No, Nonsequitorian, I need it to retain its speed, that way the trail still shows.

Author:  Asklar [ Wed Sep 14, 2011 2:11 am ]
Post subject:  Re: MOPixel won't stay put?

If it doesn't change positions it won't have speed.

Author:  TheLastBanana [ Wed Sep 14, 2011 2:21 am ]
Post subject:  Re: MOPixel won't stay put?

No, if it doesn't change positions, it will still have speed, as long as the velocity is >0.
Currently, self.StartPos and self.StartVel are storing a reference to self.Pos and self.Vel, respectively. That means every Update, you're essentially doing this:
Code:
   self.Pos = self.Pos;
   self.Vel = self.Vel;

Lua is a bit weird like that. To do what you want, set the variables like so:
Code:
   self.StartPos = Vector(self.Pos.X, self.Pos.Y);
   self.StartVel = Vector(self.Vel.X, self.Vel.Y);

Author:  Asklar [ Wed Sep 14, 2011 2:25 am ]
Post subject:  Re: MOPixel won't stay put?

Cortex Command is wierd :0

Author:  Roast Veg [ Wed Sep 14, 2011 5:19 pm ]
Post subject:  Re: MOPixel won't stay put?

Not really. Self.Pos is not a constant, and will change throughout the game. Self.Pos.X and Self.Pos.Y are constants at the time you reference them, so you have to reconstruct the Vector for the two inter-frame-constant variables in order to give a true starting value.

Which is exactly what TLB said in more words.

Author:  Awesomeness [ Fri Sep 16, 2011 2:01 am ]
Post subject:  Re: MOPixel won't stay put?

Iiiiiew references... I had to deal with them in Java using clone()... So much pain....

It worked.

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