View unanswered posts | View active topics It is currently Fri Dec 27, 2024 9:45 am



Reply to topic  [ 12 posts ] 
 Attaching emitters to people via MORays [Solved] 
Author Message
User avatar

Joined: Fri Feb 16, 2007 8:43 pm
Posts: 1695
Location: AH SHIT FUCK AUGH
Reply with quote
Post 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?


Last edited by Shook on Thu Feb 11, 2010 8:52 pm, edited 1 time in total.



Thu Feb 11, 2010 5:16 pm
Profile WWW
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post 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.


Thu Feb 11, 2010 5:26 pm
Profile
User avatar

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


Thu Feb 11, 2010 6:13 pm
Profile
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post Re: Attaching emitters to people via MORays
Exactly.

...why isn't the offset in a single vector?


Thu Feb 11, 2010 6:43 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Attaching emitters to people via MORays
I dunno.


Thu Feb 11, 2010 7:18 pm
Profile
User avatar

Joined: Fri Feb 16, 2007 8:43 pm
Posts: 1695
Location: AH SHIT FUCK AUGH
Reply with quote
Post 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. :grin:


Thu Feb 11, 2010 7:35 pm
Profile WWW
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post 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?


Fri Feb 12, 2010 12:00 am
Profile YIM
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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


Fri Feb 12, 2010 12:22 am
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post 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


Fri Feb 12, 2010 12:42 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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.


Fri Feb 12, 2010 1:01 am
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post 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.


Fri Feb 12, 2010 1:05 am
Profile
User avatar

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


Fri Feb 12, 2010 1:16 am
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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.053s | 13 Queries | GZIP : Off ]