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



Reply to topic  [ 12 posts ] 
 Homing Pixels 
Author Message
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post Homing Pixels
What function should I use to add velocity to a pixel, so that it propels itself towards an actor?


Wed Aug 20, 2014 8:53 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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.


Wed Aug 20, 2014 9:32 pm
Profile
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post Re: Homing Pixels
Well ♥♥♥♥. That sounds simple enough.


Wed Aug 20, 2014 9:48 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post 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.


Wed Aug 20, 2014 11:27 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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.


Thu Aug 21, 2014 12:41 am
Profile
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post 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.


Thu Aug 21, 2014 5:25 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Homing Pixels
Try .ElapsedSimTimeMS


Thu Aug 21, 2014 6:08 pm
Profile
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post 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


Thu Aug 21, 2014 6:40 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Homing Pixels
self.adjustTimer:Reset() after local adjustedTurnAmount definition.


Thu Aug 21, 2014 7:01 pm
Profile
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post Re: Homing Pixels
I could say that I sort of knew that that was missing... but I forgot


Thu Aug 21, 2014 7:13 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Homing Pixels
Hurp.

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


Fri Aug 22, 2014 1:15 pm
Profile
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post Re: Homing Pixels
Works now. thx


Sun Aug 24, 2014 8:29 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 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.166s | 14 Queries | GZIP : Off ]