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

Homing Pixels
http://forums.datarealms.com/viewtopic.php?f=73&t=45786
Page 1 of 1

Author:  4zK [ Wed Aug 20, 2014 8:53 pm ]
Post subject:  Homing Pixels

What function should I use to add velocity to a pixel, so that it propels itself towards an actor?

Author:  Asklar [ Wed Aug 20, 2014 9:32 pm ]
Post subject:  Re: Homing Pixels

Add the corresponding vector to the velocity of the pixel. Like, get the difference between the target and the pixel's position, set the magnitude of that vector to something that you want, and then just add it to the pixel's velocity.

That's how I'd do it though, I guess it depends on what you want.

Author:  4zK [ Wed Aug 20, 2014 9:48 pm ]
Post subject:  Re: Homing Pixels

Well ♥♥♥♥. That sounds simple enough.

Author:  Bad Boy [ Wed Aug 20, 2014 11:27 pm ]
Post subject:  Re: Homing Pixels

Yeah, you can use AddForce(...) or AddAbsForce(...) if you want but I think they're more expensive (and not as intuitive) since they have to go through some engine calculations, and the end result is probably exactly the same since in this case.

Author:  CaveCricket48 [ Thu Aug 21, 2014 12:41 am ]
Post subject:  Re: Homing Pixels

For smooth consistent homing, I have something like this:



Code:
function Create(self)

   self.adjustTimer = Timer();

   self.turnAmount = 120;

end

function Update(self)

   ...

   local dist = SceneMan:ShortestDistance(self.Pos,self.target.Pos,,SceneMan.WrapsX); -- assuming a target is already assigned

   local adjustedTurnAmount = self.turnAmount*(self.adjustTimer:ElapsedSimTimMS()/1000); -- adjusting the turn amount based on MS time in between frames

   local adjustVector = Vector(adjustTurnAmount,0):RadRotate(dist.Magnitude);

   local oldSpeed = self.Vel.Magnitude;

   self.Vel = Vector( self.Vel.X + adjustVector.X, self.Vel.Y + adjustVector.Y ):SetMagnitude(oldSpeed);

   ...

end



More or less how the (current) Nucleo Swarm and the Micro Pulsar work. Since scripts run every frame, simply adding to the projectile's velocity will make it not turn consistently in relation to in-game time, so the above script snippet adjusts the sharpness of the turn based on how much time there is in between frames.

Author:  4zK [ Thu Aug 21, 2014 5:25 pm ]
Post subject:  Re: Homing Pixels

After getting rid of an extra comma in 'local dist' definition, changing SceneMan.WrapsX to SceneMan.SceneWrapsX and fixing the typo on ElapsedSimTimeMS... according to the console, you can't call "ElapsedSimTimeMS" on a timer.

Is this a new thing or maybe a larger misconception?


In the meantime, I'll take a further look into the Micro Pulsar script.

Author:  CaveCricket48 [ Thu Aug 21, 2014 6:08 pm ]
Post subject:  Re: Homing Pixels

Try .ElapsedSimTimeMS

Author:  4zK [ Thu Aug 21, 2014 6:40 pm ]
Post subject:  Re: Homing Pixels

Oh of course, because it's a property... but the result is still the pixels twitching and then orbiting the target.

Is it possible that there's a value in the .ini code interfering with it?

EDIT: changed self.turnAmount to a lower value, should work now, maybe
EDIT2: doesn't work

Author:  CaveCricket48 [ Thu Aug 21, 2014 7:01 pm ]
Post subject:  Re: Homing Pixels

self.adjustTimer:Reset() after local adjustedTurnAmount definition.

Author:  4zK [ Thu Aug 21, 2014 7:13 pm ]
Post subject:  Re: Homing Pixels

I could say that I sort of knew that that was missing... but I forgot

Author:  CaveCricket48 [ Fri Aug 22, 2014 1:15 pm ]
Post subject:  Re: Homing Pixels

Hurp.

Change :RadRotate(dist.Magnitude) to :RadRotate(dist.AbsRadAngle)

Author:  4zK [ Sun Aug 24, 2014 8:29 pm ]
Post subject:  Re: Homing Pixels

Works now. thx

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