Data Realms Fan Forums http://45.55.195.193/ |
|
CastMORay [QUESTION CHANGE!] http://45.55.195.193/viewtopic.php?f=73&t=26974 |
Page 1 of 1 |
Author: | Asklar [ Mon Dec 05, 2011 12:15 am ] |
Post subject: | 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? |
Author: | CaveCricket48 [ Mon Dec 05, 2011 12:33 am ] |
Post subject: | 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. |
Author: | Asklar [ Mon Dec 05, 2011 12:35 am ] |
Post subject: | Re: CastMORay |
MovableMan:GetMOFromID(self.Ray).RootID == self.ID? |
Author: | CaveCricket48 [ Mon Dec 05, 2011 12:40 am ] |
Post subject: | Re: CastMORay |
Yep, assuming self is the parent object. |
Author: | Asklar [ Mon Dec 05, 2011 12:41 am ] |
Post subject: | Re: CastMORay |
Ok, gone to test. BRB. |
Author: | Asklar [ Mon Dec 05, 2011 1:01 am ] |
Post subject: | 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)) |
Author: | CaveCricket48 [ Mon Dec 05, 2011 2:15 am ] |
Post subject: | Re: CastMORay |
You did "MovableMan:GetMOFromID(self.Ray)" instead of "MovableMan:GetMOFromID(self.Ray).RootID" |
Author: | Asklar [ Mon Dec 05, 2011 3:02 am ] |
Post subject: | Re: CastMORay |
Why didn't I see that? Testing and BRB. |
Author: | Asklar [ Mon Dec 05, 2011 3:12 am ] |
Post subject: | 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. |
Author: | CaveCricket48 [ Mon Dec 05, 2011 4:02 am ] |
Post subject: | Re: CastMORay |
You also forgot to check if the ray doesn't hit anything (self.Ray ~= 255). |
Author: | Asklar [ Mon Dec 05, 2011 5:20 am ] |
Post subject: | 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. |
Author: | Asklar [ Mon Dec 05, 2011 7:02 pm ] |
Post subject: | Re: CastMORay |
I was right, the thing was the self.VectorToTraceAlong. Just changed it to particle.Vel and it works perfectly. |
Author: | CaveCricket48 [ Tue Dec 06, 2011 5:47 pm ] |
Post subject: | 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. |
Author: | Asklar [ Tue Dec 06, 2011 6:49 pm ] |
Post subject: | 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) |
Author: | CaveCricket48 [ Tue Dec 06, 2011 6:53 pm ] |
Post subject: | 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. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |