Author |
Message |
4zK
Joined: Mon Oct 11, 2010 1:15 pm Posts: 594 Location: Finlandia
|
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 |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
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 |
|
|
4zK
Joined: Mon Oct 11, 2010 1:15 pm Posts: 594 Location: Finlandia
|
Re: Homing Pixels
Well ♥♥♥♥. That sounds simple enough.
|
Wed Aug 20, 2014 9:48 pm |
|
|
Bad Boy
Joined: Fri Sep 10, 2010 1:48 am Posts: 666 Location: Halifax, Canada
|
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 |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
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 |
|
|
4zK
Joined: Mon Oct 11, 2010 1:15 pm Posts: 594 Location: Finlandia
|
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 |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Homing Pixels
Try .ElapsedSimTimeMS
|
Thu Aug 21, 2014 6:08 pm |
|
|
4zK
Joined: Mon Oct 11, 2010 1:15 pm Posts: 594 Location: Finlandia
|
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 |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Homing Pixels
self.adjustTimer:Reset() after local adjustedTurnAmount definition.
|
Thu Aug 21, 2014 7:01 pm |
|
|
4zK
Joined: Mon Oct 11, 2010 1:15 pm Posts: 594 Location: Finlandia
|
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 |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Homing Pixels
Hurp.
Change :RadRotate(dist.Magnitude) to :RadRotate(dist.AbsRadAngle)
|
Fri Aug 22, 2014 1:15 pm |
|
|
4zK
Joined: Mon Oct 11, 2010 1:15 pm Posts: 594 Location: Finlandia
|
Re: Homing Pixels
Works now. thx
|
Sun Aug 24, 2014 8:29 pm |
|
|
|