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



Reply to topic  [ 15 posts ] 
 CastMORay [QUESTION CHANGE!] 
Author Message
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 CastMORay [QUESTION CHANGE!]
What does it return?

Let's say I'm using it on particles being fired to me and if they return self then I want to dodge it.

Should I do something like if self.Ray == self then or if self.Ray.ID == self.ID then?

/\-------------------Older doubtz---------------------------/\
-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-,_:;-.,_:;-.,-;
-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-,_:;-.,_:;-.,-;
-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-,_:;-.,_:;-.,-;
-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-.,_:;-,_:;-.,_:;-.,-;
\/-------------------New doubtz----------------------------\/

Does CastMORay ignore terrain? If it does, is there a way to make it get stopped by terrain?


Last edited by Asklar on Mon Dec 05, 2011 11:46 pm, edited 1 time in total.



Mon Dec 05, 2011 12:15 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: CastMORay
It returns an MOID. You should grab the MO of that ID, find the parent MO, and compare the parent MO's ID to self.RootID.


Mon Dec 05, 2011 12:33 am
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: CastMORay
MovableMan:GetMOFromID(self.Ray).RootID == self.ID?


Mon Dec 05, 2011 12:35 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: CastMORay
Yep, assuming self is the parent object.


Mon Dec 05, 2011 12:40 am
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: CastMORay
Ok, gone to test.
BRB.


Mon Dec 05, 2011 12:41 am
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: CastMORay
Not working, it doesn't show errors or anything.

Code:
      if not self:IsPlayerControlled() then
         for particle in MovableMan.Particles do
            self.VectorToTraceAlong = Vector(particle.Vel.X*15,particle.Vel.Y*15)
            self.Ray = SceneMan:CastMORay(particle.Pos,self.VectorToTraceAlong,particle.ID,0,false,0)
            if MovableMan:GetMOFromID(self.Ray) == self.ID then
               self.Vel.X = 15*math.random(-1,1)
            end
         end
      end


This is the code I'm using, it's like some sort of primitive and reactive AI.

(Note it is inside the function Update(self))


Mon Dec 05, 2011 1:01 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: CastMORay
You did "MovableMan:GetMOFromID(self.Ray)" instead of "MovableMan:GetMOFromID(self.Ray).RootID"


Mon Dec 05, 2011 2:15 am
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: CastMORay
Why didn't I see that?

Testing and BRB.


Mon Dec 05, 2011 3:02 am
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: CastMORay
Changed it again, the code looks like:
Code:
      if not self:IsPlayerControlled() then
         for particle in MovableMan.Particles do
            self.VectorToTraceAlong = Vector(particle.Vel.X*15,particle.Vel.Y*15)
            self.Ray = SceneMan:CastMORay(particle.Pos,self.VectorToTraceAlong,particle.ID,0,false,0)
            if MovableMan:GetMOFromID(self.Ray).RootID == self.ID then
               self.Vel.X = 15*math.random(-1,1)
            end
         end
      end


It's wierd. It works sometimes. If I shoot at it it might work, if I don't it sometimes works anyway. And I keep getting a very vague error in the lua console which says "attempt to index a nil value" in the if MovableMan:Get... line.

Maybe it has to do with the self.VectorToTraceAlong, but I'm not sure.


Mon Dec 05, 2011 3:12 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: CastMORay
You also forgot to check if the ray doesn't hit anything (self.Ray ~= 255).


Mon Dec 05, 2011 4:02 am
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: CastMORay
Changed the code to this:
Code:
      if not self:IsPlayerControlled() then
         for particle in MovableMan.Particles do
            self.DodgeDistance = SceneMan:ShortestDistance(self.Pos,particle.Pos,true).Magnitude
            if self.DodgeDistance <= 700 then   
               self.VectorToTraceAlong = Vector(particle.Vel.X*15,particle.Vel.Y*15)
               self.Ray = SceneMan:CastMORay(particle.Pos,self.VectorToTraceAlong,particle.ID,0,false,0)
               if self.Ray ~= 255 then
                  if MovableMan:GetMOFromID(self.Ray).RootID == self.ID then
                  self.Vel.X = 15*math.random(-1,1)
                  end
               end
            end
         end
      end


But it's not working either.


Mon Dec 05, 2011 5:20 am
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: CastMORay
I was right, the thing was the self.VectorToTraceAlong. Just changed it to particle.Vel and it works perfectly.


Mon Dec 05, 2011 7:02 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: CastMORay [QUESTION CHANGE!]
Quote:
CastMORay
Traces along a vector and returns MOID of the first non-ignored non-NoMOID MO encountered. If a non-air terrain pixel is encountered first, g_NoMOID will be returned.

Arguments:
-The starting position.
-The vector to trace along.
-An MOID to ignore. Any child MO's of this MOID will also be ignored.
-A specific material ID to ignore hits with.
-Whether to ignore all terrain hits or not.
-For every pixel checked along the line, how many to skip between them for optimization reasons. 0 = every pixel is checked.

Return value:
The MOID of the hit non-ignored MO, or g_NoMOID if terrain or no MO was hit.

Setting fifth argument to false should work. And if it doesn't, try true.


Tue Dec 06, 2011 5:47 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: CastMORay [QUESTION CHANGE!]
Tried them both, not working.

I used another ray to determine the length of the MORay in order to get a length that wouldn't go across terrain, but still it's not working.

Code:
self.DetectTerrain = SceneMan:CastObstacleRay(self.Weapon.Pos,Vector(650*self.Reverse,0):RadRotate(self.RotAngleFactor),Vector(),Vector(),self.ID,0,0)

self.DetectEnemy = SceneMan:CastMORay(self.Weapon.Pos,Vector(self.DetectTerrain,0):RadRotate(self.RotAngleFactor),self.ID,0,true,0)


Tue Dec 06, 2011 6:49 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: CastMORay [QUESTION CHANGE!]
You should cast a strength ray instead of an obstacle ray, since, if I'm thinking about this correctly, obstacle rays cast 2 rays at once (one for MOs and one for terrain), which would slow things down a lot. Also, a strength ray is easier to work with.


Tue Dec 06, 2011 6:53 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 15 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.309s | 13 Queries | GZIP : Off ]