Data Realms Fan Forums http://45.55.195.193/ |
|
Attaching emitters to people via MORays [Solved] http://45.55.195.193/viewtopic.php?f=73&t=17802 |
Page 1 of 1 |
Author: | Shook [ Thu Feb 11, 2010 5:16 pm ] |
Post subject: | Attaching emitters to people via MORays [Solved] |
So yeah, i'm trying to do some incendiary rounds for a gun. This involves making the bullet attach a burning emitter to the point of impact. However, i just can't figure out that damn AttachEmitter function! The relevant code looks like so: Code: self.pointed = MovableMan:GetMOFromID(SceneMan:CastMORay(self.Pos, (self.Vel*(1/3)), self.ID, 0, true, 1)) self.burnwound = CreateAEmitter("Burn Wound"); self.burnwound.RotAngle = math.atan(self.Vel.Y/self.Vel.X); if self.pointed ~= nil and self.pointed.ClassName ~= "MOPixel" and self.pointed.ClassName ~= "MOSParticle" then local impactDist = SceneMan:CastObstacleRay(self.Pos, self.Vel/3, Vector(0, 0), Vector(0, 0), self.ID, 0, 0) self.burnwound.Pos.X = self.Pos.X + (math.cos(self.burnwound.RotAngle)*impactDist); self.burnwound.Pos.Y = self.Pos.Y + (math.sin(self.burnwound.RotAngle)*impactDist); self.pointed:AttachEmitter(self.burnwound, Vector(0, 0)); self.ToDelete = true; end And it crashes at the AttachEmitter line, claiming something about "a nil value". I suspect that the problem is either in that line, or in my method of acquiring the target MO. Problem is, i can't find that problem. halp? |
Author: | findude [ Thu Feb 11, 2010 5:26 pm ] |
Post subject: | Re: Attaching emitters to people via MORays |
AttachEmitter is pretty much just as broken as all other Lua attachable support. Better make the emitters Lua'd too, and give them the offset from the parent to orient themselves on. |
Author: | CaveCricket48 [ Thu Feb 11, 2010 6:13 pm ] |
Post subject: | Re: Attaching emitters to people via MORays |
Some Lua functions don't work in the current build of CC. The script below is what I use: Code: function Create(self) self.LifeTimer = Timer(); self.PoisonTimer = Timer(); self.poisonstrength = 10; self.target = nil; self.targetclass = nil; self.stickpositionX = 0; self.stickpositionY = 0; self.stickrotation = 0; self.stickdirection = 0; end function Update(self) if self.target == nil then local stickobject = SceneMan:CastMORay(self.Pos,Vector(5,0):RadRotate(self.RotAngle),255,0,false,0); if stickobject ~= 255 then self.target = MovableMan:GetMOFromID(stickobject); self.targetclass = self.target.ClassName; self.stickpositionX = self.Pos.X-self.target.Pos.X; self.stickpositionY = self.Pos.Y-self.target.Pos.Y; self.stickrotation = self.target.RotAngle; self.stickdirection = self.RotAngle; self.LifeTimer:Reset(); end elseif self.target ~= nil and self.target.ID ~= 255 then self.ToDelete = false; self.ToSettle = false; self.Pos = self.target.Pos + Vector(self.stickpositionX,self.stickpositionY):RadRotate(self.target.RotAngle-self.stickrotation); self.RotAngle = self.stickdirection+(self.target.RotAngle-self.stickrotation); self.Vel = Vector(0,0); self.PinStrength = 1000; else self.ToDelete = true; end -- This makes the sticky object delete itself after 10 seconds if self.LifeTimer:IsPastSimMS(10000) then self.ToDelete = true; end end This script is attached to any movable object that you want to "stick" to things. What is does is that it casts an MORay, and when the ray hits an MO, the script stores the target's rotation, the rotation of itself, and the distance in between the two. Then the script constantly updates the "sticky" object's position and rotation based upon the three previously stored values to make it look like it's sticking. |
Author: | findude [ Thu Feb 11, 2010 6:43 pm ] |
Post subject: | Re: Attaching emitters to people via MORays |
Exactly. ...why isn't the offset in a single vector? |
Author: | CaveCricket48 [ Thu Feb 11, 2010 7:18 pm ] |
Post subject: | Re: Attaching emitters to people via MORays |
I dunno. |
Author: | Shook [ Thu Feb 11, 2010 7:35 pm ] |
Post subject: | Re: Attaching emitters to people via MORays |
Oh, so it's broken? That explains all the crashes. >.> Also, thanks a bunch Cricket, you just saved me from a lot of work. |
Author: | Djinn [ Fri Feb 12, 2010 12:00 am ] |
Post subject: | Re: Attaching emitters to people via MORays [Solved] |
Is there any way to make that code only function only on a specific actor? Like ONLY sticking if it hits 'Robot 1'. Or, for instance, sticking only to robots/things using Metal as their material? |
Author: | Grif [ Fri Feb 12, 2010 12:22 am ] |
Post subject: | Re: Attaching emitters to people via MORays [Solved] |
if self.targetclass == "AHuman" and self.target.PresetName == "Robot 1" then Alternately, you can make a list of presetnames of actors that you want a script to affect, then do a string.find comparison, as here: list = {"Robot 1","Robot 2","Rocket MK1"}; if string.find(self.target.PresetName,list) == true then |
Author: | Mind [ Fri Feb 12, 2010 12:42 am ] |
Post subject: | Re: Attaching emitters to people via MORays [Solved] |
RadRotate = radial rotate right? So it's just turning the object a specific amount? Just checking Also, just trying to break down this line of code. Code: local stickobject = SceneMan:CastMORay(self.Pos,Vector(5,0):RadRotate(self.RotAngle),255,0,false,0); Edit#2: And uh one more thing. It says if target == nil, so how does it cast an moray at the target if it doesn't know the target yet? Or better yet, how does it know in what direction to shoot the MORay for it to collide with something? Or doesn't it |
Author: | Grif [ Fri Feb 12, 2010 1:01 am ] |
Post subject: | Re: Attaching emitters to people via MORays [Solved] |
It checks that there is no target before casting a ray. The ray itself is just cast along the direction of motion; it's a script meant to be applied to projectiles. |
Author: | Mind [ Fri Feb 12, 2010 1:05 am ] |
Post subject: | Re: Attaching emitters to people via MORays [Solved] |
O...ok thanks. Just one thing: RadRotate just a simple rotating function, right? Cuz I see it rotates the point 5,0 to match up with its RotAngle. |
Author: | CaveCricket48 [ Fri Feb 12, 2010 1:16 am ] |
Post subject: | Re: Attaching emitters to people via MORays [Solved] |
RadRotate rotates vectors while maintaining their magnitude, so rotating a vector (RadRotate) based upon something's rotation (RotAngle) woud be kind of like putting an offset. Edit: Yes it's a simple rotating function, for vectors. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |