|
Page 1 of 1
|
[ 15 posts ] |
|
CastMORay [QUESTION CHANGE!]
Author |
Message |
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
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 |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
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 |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: CastMORay
MovableMan:GetMOFromID(self.Ray).RootID == self.ID?
|
Mon Dec 05, 2011 12:35 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: CastMORay
Yep, assuming self is the parent object.
|
Mon Dec 05, 2011 12:40 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: CastMORay
Ok, gone to test. BRB.
|
Mon Dec 05, 2011 12:41 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
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 |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: CastMORay
You did "MovableMan:GetMOFromID(self.Ray)" instead of "MovableMan:GetMOFromID(self.Ray).RootID"
|
Mon Dec 05, 2011 2:15 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: CastMORay
Why didn't I see that?
Testing and BRB.
|
Mon Dec 05, 2011 3:02 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
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 |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: CastMORay
You also forgot to check if the ray doesn't hit anything (self.Ray ~= 255).
|
Mon Dec 05, 2011 4:02 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
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 |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
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 |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
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 |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
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 |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
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 |
|
|
|
|
Page 1 of 1
|
[ 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
|
|