Data Realms Fan Forums
http://45.55.195.193/

Floating object attached to assigned actor.
http://45.55.195.193/viewtopic.php?f=73&t=18306
Page 1 of 2

Author:  ajlw [ Wed Mar 31, 2010 10:06 pm ]
Post subject:  Floating object attached to assigned actor.

See title.


An event triggers an animation loop displayed as a HUD status bar (Like the Jetpack fuel bar?)

It spawns fine and sticks above the character and all that...

... it just doesn't stick TO the character, and stays in mid air if the player moves...

So, basically, I have no idea how to do this and the search function has too much scatter and needless information about guns =.=

Author:  Grif [ Wed Mar 31, 2010 10:11 pm ]
Post subject:  Re: Floating object attached to assigned actor.

Find the nearest actor using SceneMan:ShortestDistance and (if it's a custom actor, check that the presetnames match) use it as the 'zero' vector to modify by your deltaY to get a point above it.

Author:  ajlw [ Wed Mar 31, 2010 10:12 pm ]
Post subject:  Re: Floating object attached to assigned actor.

Grif wrote:
Find the nearest actor using SceneMan:ShortestDistance and (if it's a custom actor, check that the presetnames match) use it as the 'zero' vector to modify by your deltaY to get a point above it.



No no no, I mean, I already got it to spawn on the right spot, just not to stick to it.


Should I make it an attachable instead of a particle/pixel/thingitisnow ?

Author:  Duh102 [ Wed Mar 31, 2010 10:15 pm ]
Post subject:  Re: Floating object attached to assigned actor.

You can't permanently attach anything with Lua, you have to reset it's position every frame (or every 50 ms or whatever).

Author:  Grif [ Wed Mar 31, 2010 10:20 pm ]
Post subject:  Re: Floating object attached to assigned actor.

Just do
function Update(self)
self.Pos = Vector(actor.Pos.X, actor.Pos.Y - howevermanypixels);
end

Author:  ajlw [ Wed Mar 31, 2010 10:28 pm ]
Post subject:  Re: Floating object attached to assigned actor.

*Facepalms* D'ah!

T-thanks...

Edit:

Is it, like, possible to make a MOSParticle with a script that does that?
Or do I need to make it an attachable after all?

Author:  Grif [ Wed Mar 31, 2010 10:55 pm ]
Post subject:  Re: Floating object attached to assigned actor.

It's quite possible, though I'd need more specifics on exactly how you're doing all this to tell you just how.

Is it a custom actor, or a weapon effect, or what?

Author:  Duh102 [ Wed Mar 31, 2010 11:13 pm ]
Post subject:  Re: Floating object attached to assigned actor.

That which is following the actor can be anything, if that's your question.

Author:  ajlw [ Wed Mar 31, 2010 11:18 pm ]
Post subject:  Re: Floating object attached to assigned actor.

INI:

Code:
AddEffect = MOSParticle
   PresetName = Stat
   Mass = 0.001
   GlobalAccScalar = 0.0
   LifeTime = 5150
   HitsMOs = 0
   GetsHitByMOs = 0
   ScriptPath = ActionHeroSoldier.rte/Devices/PartEff.lua
   SpriteFile = ContentFile
      FilePath = TesterBreachC4.rte/Devices/Timer.bmp
   FrameCount = 7
   SpriteAnimMode = 0
   SpriteAnimDuration = 725
   SpriteOffset = Vector
      X = -10
      Y = -8
   Atom = Atom
      Material = Material
         CopyOf = Air
      TrailLength = 0

LUA:
Code:
function Create(self)
local curdist = 50
for i = 1,MovableMan:GetMOIDCount()-1 do
   gun = MovableMan:GetMOFromID(i);
   if gun.ClassName == "HDFirearm" and gun.PresetName == "C-4 placer" and (gun.Pos-self.Pos).Magnitude < curdist then
      actor = MovableMan:GetMOFromID(gun.RootID);
    if MovableMan:IsActor(actor) then
      self.parent = ToActor(actor);
         local Stat = CreateMOSParticle("Stat");
            Stat.Pos = self.parent.AboveHUDPos + Vector(0,1);
            MovableMan:AddParticle(Stat);
         end
      end
   end
end



As you could probably guess the lua is attached to the fired projectile (It's a timer charge that shows how long it takes before detonation is possible by manual control) and not the gun or the actor itself.

Should I apply the :

Code:
function Update(self)
   self.Pos = Vector(actor.Pos.X, actor.Pos.Y);
end


to a new LUA file and attach that to the MOSParticle 'Stat' ?

It works, though, but it'll stop working if I stop moving.

Author:  Duh102 [ Wed Mar 31, 2010 11:20 pm ]
Post subject:  Re: Floating object attached to assigned actor.

Yeah, if I'm reading you you want the Stat particle to stay with the Actor, in which case you would put that Lua attached to Stat.

Author:  ajlw [ Wed Mar 31, 2010 11:23 pm ]
Post subject:  Re: Floating object attached to assigned actor.

*Facedesk* I edited just as you posted.


Uhm, well, it works, sort of.

It just vanishes if I stay standing still.

Author:  PhantomAGN [ Wed Mar 31, 2010 11:25 pm ]
Post subject:  Re: Floating object attached to assigned actor.

ajlw wrote:
(...)to a new LUA file and attach that to the MOSParticle 'Stat' ?
No.
Stick that code in the same Lua document.
Do not attach another separate Lua document.
I hope I understood you.

Edit:
Is the particle's lifetime a factor in the disappearing?

Author:  ajlw [ Wed Mar 31, 2010 11:28 pm ]
Post subject:  Re: Floating object attached to assigned actor.

6 seconds, so no...


And if I do put it in the same lua document, I'm pretty sure the round fired (The bomb) will stick above my head instead... as the lua is for the round, and the particle is something different from the round and shouldn't be affiliated with the script written for the round...

... r-right?


Edit:

Tried it.

Me exploding into 50000 fleshy bits should make it obvious enough.

Author:  Grif [ Wed Mar 31, 2010 11:32 pm ]
Post subject:  Re: Floating object attached to assigned actor.

Okay, then this is pretty simple.

Have the lua attached to the fired shot spawn the MOSParticle.

That MOSParticle will have a script to find the nearest actor (look at the homing missile for a quick example), which it will then designate as the "target". Then, just use the update position code to keep it attached.

Author:  ajlw [ Wed Mar 31, 2010 11:34 pm ]
Post subject:  Re: Floating object attached to assigned actor.

I shouldn't be doing this at 0:33 AM after a party... urgh.

Kay, here goes nothing...

Edit:

Nope, too tired.
Will try tommorow, at work, or something.

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