Data Realms Fan Forums http://45.55.195.193/ |
|
Understanding CastStrengthRay http://45.55.195.193/viewtopic.php?f=73&t=30651 |
Page 1 of 1 |
Author: | ryry1237 [ Sat Mar 10, 2012 1:25 am ] |
Post subject: | Understanding CastStrengthRay |
As I understand it, the general idea of CastStrengthRay is to look around for any terrain pieces that are stronger than a specified value and to then return true or not. According to the Wiki, CastStrengthRay is used as such: Arguments: - The starting position. - The vector to trace along. - The strength value of screen any found to be equal or more than will terminate the ray. - A reference to the vector screen will be filled out with the absolute location of the found terrain pixel of less than or equal to above strength. - For every pixel checked along the line, how many to skip between them for optimization reasons. 0 = every pixel is checked. - A material ID to ignore, IN ADDITION to Air. - Whether the ray should wrap around the scene if it crosses a seam. Return value: - Whether a material of equal or more strength was found along the ray. If not, the fourth parameter have been set to last position of the ray. So it's really the fourth point that I'm confused about. What would a reference be, and what is a vector screen? I also found an example although I still don't quite understand why the fourth value is Vector (0,0) (or what will happen if I change it) Code: local terrainRaycast = SceneMan:CastStrengthRay(self.Pos,Vector(self.Vel.X,self.Vel.Y),10,Vector(0,0),0,0,SceneMan.SceneWrapsX) Any help would be appreciated! |
Author: | TheLastBanana [ Sat Mar 10, 2012 1:33 am ] |
Post subject: | Re: Understanding CastStrengthRay |
Basically, a reference means you're giving it hitPos itself instead of just a copy of hitPos. That way, the function can modify hitPos for you and then you can use that new data. Code: local hitPos = Vector(); local terrainRaycast = SceneMan:CastStrengthRay(self.Pos,Vector(self.Vel.X,self.Vel.Y),10,hitPos,0,0,SceneMan.SceneWrapsX); By setting that argument to Vector(0,0), you're giving it a throwaway value of sorts - you can't access it afterward. In other words, you don't care about where the ray ends, so it'll just discard the data. |
Author: | ryry1237 [ Sat Mar 10, 2012 2:56 am ] |
Post subject: | Re: Understanding CastStrengthRay |
So basically, if I want to know the exact point of where the ray hits, I add the hitPos part, but if I just want to know whether the ray hits or not, I just use Vector(0,0) right? Assuming the above is true, CastStrengthRay will return a true/false value and a vector? |
Author: | TheLastBanana [ Sat Mar 10, 2012 3:43 am ] |
Post subject: | Re: Understanding CastStrengthRay |
Functions can only return one value - in this case, it's a Boolean (true/false) value. That's why you have to pass in the vector as a reference. To your first question, though, yes, just use Vector(0,0) (or just Vector(), since that's the same thing) if you don't care where it hits. |
Author: | ryry1237 [ Sat Mar 10, 2012 4:06 am ] |
Post subject: | Re: Understanding CastStrengthRay |
Alright thanks! |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |