Author |
Message |
Awesomeness
Joined: Sat Jun 19, 2010 5:02 pm Posts: 331 Location: Mekkan
|
ObstacleRays and raping/creating terrain
I have a few questions.
Apparently obstacle rays are very useful in making guns. My vague understanding is you give it an angle and a location and it figures out if and where it hits something. The wiki barely even mentions it. What are they exactly and how do I use them?
How can I rape terrain manually, as in I rip apart the land at say, a point, or a box, or a circle. I don't want it to disappear, just to collapse and make some disappear and others turn into little falling land bits. (but knowing how to do both would be nice)
And lastly, how can I create land at a certain location? Not like a cement gun, I want it to make terrain instantly appear without having to settle.
|
Thu Jul 15, 2010 7:54 pm |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: ObstacleRays and raping/creating terrain
The way CC's "Rays" work is by you stating a starting position, and a direction for the ray to go as well as how long to cast the ray.
The starting position is a Vector, and the direction/magnitude of ray is also a vector. (though, mathmatically, would it be considered a line segment, not a ray?)
The each ray as its own special arguments that effect its behavior.
To destroy terrain, you could spawn ini object that will damage terrain (bombs, sharp MOPixels, ect), or use the function "MovableMan:EraseFromTerrain()" (or something like that) on an object, which will clear terrain that covers any part of the object.
To "create" terrain, you could either use "pointer.ToSettle = true" on an MOPixel or and MOSParticle to instantly turn it to terrain. MOPixels will settle into a single pixel of terrain (duh) and MOSParticles will retain their sprite shape and size as terrain.
|
Thu Jul 15, 2010 8:21 pm |
|
|
Awesomeness
Joined: Sat Jun 19, 2010 5:02 pm Posts: 331 Location: Mekkan
|
Re: ObstacleRays and raping/creating terrain
I used this tutorial to get a weak grasp at obstacle rays, but I don't understand what the third and fourth arguments ("A reference to...") mean. Code: CastObstacleRay
Traces along a vector and returns the length of how far the trace went without hitting any non-ignored terrain material or MOID at all.
Arguments:
* The starting position. * The vector to trace along. * A reference to the vector screen will be filled out with the absolute location of the first obstacle, or the end of the ray if none was hit. * A reference to the vector screen will be filled out with the absolute location of the last free position before hitting an obstacle, or the end of the ray if none was hit. This is only altered if thre are any free pixels encountered. * An MOID to ignore. Any child MO's of this MOID will also be ignored. * A specific material ID to ignore hits with. * For every pixel checked along the line, how many to skip between them for optimization reasons. 0 = every pixel is checked.
Return value:
How far along, in pixel units, the ray the pixel of any obstacle was encountered. If no pixel of the right material was found, < 0 is returned. If an obstacle on the starting position was encountered, 0 is returned. Could you clear things up for me? Thanks.
|
Thu Jul 15, 2010 9:19 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: ObstacleRays and raping/creating terrain
That's just long mumbo-jumbo for "a vector coordinate."
|
Thu Jul 15, 2010 9:52 pm |
|
|
Awesomeness
Joined: Sat Jun 19, 2010 5:02 pm Posts: 331 Location: Mekkan
|
Re: ObstacleRays and raping/creating terrain
But what do I put there, and what does it do with it?
|
Fri Jul 16, 2010 1:21 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: ObstacleRays and raping/creating terrain
The typical implementation is something like this: local pointhit,otherpoint = Vector(0,0),Vector(0,0); SceneMan:CastObstacleRay(stuff,stuff,pointhit,otherpoint) etc etc
and then you can just use pointhit or otherpoint as coordinates, because if you use them as arguments they'll be changed by the execution of the function.
|
Fri Jul 16, 2010 1:43 am |
|
|
Awesomeness
Joined: Sat Jun 19, 2010 5:02 pm Posts: 331 Location: Mekkan
|
Re: ObstacleRays and raping/creating terrain
You didn't answer my question very well. I still don't know what those two arguments are/do/mean. What am I supposed to give it? I know it's a vector, but what is that vector representing? I know it has something to do with where it hits, but I don't see why you would give the obstacle ray the point at which the ray hits something if you're using it to find that point in the first place. I'm missing something, because that's what the documentation I showed you sounds like it's saying. I'm so frustrated...
|
Fri Jul 16, 2010 11:22 pm |
|
|
Duh102
happy carebear mom
Joined: Tue Mar 04, 2008 1:40 am Posts: 7096 Location: b8bbd5
|
Re: ObstacleRays and raping/creating terrain
There are four vectors mentioned in the arguments description. 1. The position to start from 2. The direction to go along 3. A vector variable to fill with the location of the first hit object 4. A vector variable to fill with the last position the obstacle ray checked before it hit something
|
Fri Jul 16, 2010 11:50 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: ObstacleRays and raping/creating terrain
You're giving the function two BLANK vectors as arguments. By executing the function, those two vectors will be filled out; then you access those vectors as your return data.
You're feeding the function a null vector in exchange for a filled out vector.
|
Sat Jul 17, 2010 1:14 am |
|
|
Awesomeness
Joined: Sat Jun 19, 2010 5:02 pm Posts: 331 Location: Mekkan
|
Re: ObstacleRays and raping/creating terrain
Oh, I get it. Thanks. I didn't expect it to be that way because that isn't conventional in other programming languages such as Java. Sorry for all the trouble...
|
Sat Jul 17, 2010 2:22 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: ObstacleRays and raping/creating terrain
It's a bit convoluted, but most of the rest of lua is more straightforward. Just a hiccup in Data's implementation of scripting.
|
Sat Jul 17, 2010 2:37 am |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: ObstacleRays and raping/creating terrain
Heh, limbs and inventory.
|
Sat Jul 17, 2010 2:38 am |
|
|
|