Data Realms Fan Forums http://45.55.195.193/ |
|
Terrain Rape http://45.55.195.193/viewtopic.php?f=73&t=21435 |
Page 1 of 1 |
Author: | Asklar [ Tue Feb 08, 2011 6:47 am ] |
Post subject: | Terrain Rape |
I've been learning some Lua, but I don't know enough for a code I want to make. You know, I've been making guns for a new mod, but some of them seriously rape terrain in an epic way. Is there any code to make bullets less-terrain-rapers but staying with the same power? |
Author: | 411570N3 [ Tue Feb 08, 2011 7:09 am ] |
Post subject: | Re: Terrain Rape |
Code: function Update(self) if self:GetAltitude(0,5) < 1 then self.Sharpness = 1 end end |
Author: | Asklar [ Tue Feb 08, 2011 7:30 am ] |
Post subject: | Re: Terrain Rape |
Would you mind explaining me how does the code work? I mean, I apreciate that you helped me on that, but I would apreciate more to learn rather than copying. |
Author: | Geti [ Tue Feb 08, 2011 7:52 am ] |
Post subject: | Re: Terrain Rape |
If the particle is within a pixel of the ground, its sharpness drops to 1. That doesn't work with bullets travelling upwards nearly as well, and still gives you some funny penetration at times. You're better off using rays, but I can't remember the function now :/ If no-one's helped you in a few hours and I drop back into this topic, I'll look them up but I've got to dash. |
Author: | Asklar [ Tue Feb 08, 2011 8:06 am ] |
Post subject: | Re: Terrain Rape |
In a few hours I'll be sleeping, in here it's 4 AM. Lol. Ok, I'll see tomorrow and try to learn more at coding. |
Author: | Geti [ Tue Feb 08, 2011 10:07 am ] |
Post subject: | Re: Terrain Rape |
Code: function Update(self) local vel = Vector(self.Vel.X,self.Vel.Y):SetMagnitude(20); if SceneMan:CastStrengthRay(self.Pos,vel,10,nil,5,0,true) == true then self.Sharpness = 1; end end The idea here is to cast an strength ray - a ray that is blocked by all terrain pixels of an equal or higher strength to the one specified - to search from our position (self.Pos) in the direction of our velocity 20 pixels ahead (using the local variable "vel" for simplicity), at 5 pixel intervals (to cut down on the amount of checks; we don't need it pixel perfect) for any material of strength 10 or higher. If we find such an obstruction, we cut down our sharpness. It's bedtime, and I haven't written lua for CC for a while, so don't vouch on this code working, but that's the basic setup of what you'd do for it to work in any direction. |
Author: | Asklar [ Tue Feb 08, 2011 8:27 pm ] |
Post subject: | Re: Terrain Rape |
Material with strength 10 or higher? You mean structural integrity or something like that? And the syntax of this line kinda confuse me: Code: if SceneMan:CastStrengthRay(self.Pos,vel,10,nil,5,0,true) == true then What do the values in the brackets refer to? It is like "Cast rays from self.pos, with the vel = 20, checking for 10 strength, nil (?), every 5 pixels, 0(?), true(?)"? |
Author: | Geti [ Wed Feb 09, 2011 1:34 am ] |
Post subject: | Re: Terrain Rape |
Code: SceneMan:CastStrengthRay( --the function call self.Pos, --from our position vel, --along the normalised velocity 10, --for strength >=10 nil, --we don't need a variable here, but if we passed a pointer to a vector the function would fill it out with the last free pixel 5, --step 5 pixels each time 0, --don't ignore any material IDs true --wrap around the scene ) == true --when we're blocked, go on. |
Author: | mail2345 [ Wed Feb 09, 2011 2:06 am ] |
Post subject: | Re: Terrain Rape |
Code: true --wrap around the scene Shouldn't that be SceneMan.Scene.WrapsX, to check if the scene actually wraps? |
Author: | Asklar [ Wed Feb 09, 2011 8:32 am ] |
Post subject: | Re: Terrain Rape |
I tried the code, but it doesn't work because the projectile I fire goes still too fast and has a lot of mass. I prefer to reduce it's speed, so how do I reduce it? With self.Velocity = 1? |
Author: | 411570N3 [ Wed Feb 09, 2011 8:56 am ] |
Post subject: | Re: Terrain Rape |
Velocity must be a vector, so you'd want something like self.Velocity = self.Velocity:Normalised * <Number>, or whatever the correct syntax is. |
Author: | Asklar [ Wed Feb 09, 2011 9:01 am ] |
Post subject: | Re: Terrain Rape |
Yeah, I knew velocity was a vector but I didn't knew how to express it. |
Author: | Geti [ Wed Feb 09, 2011 11:03 am ] |
Post subject: | Re: Terrain Rape |
Mail, you dog. It should indeed, but I blame not working with CC for going on a year straight for my slip ups these days You might have to do self.Velocity = Vector(self.Velocity.X,self.Velocity.Y):SetMagnitude(20); or whatever you want the speed to be set to, and then set a flag (self.flag) to true and check that it's not true at the start of the if statement (it'll be nil when not defined). I'm not sure you can call functions on your vectors directly, I remember having issues with it but that was a few builds ago. Not defining the flag until you're setting it isn't really good practice, but you're not paying for that tiny piece of memory until it is defined this way. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |