View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:30 am



Reply to topic  [ 13 posts ] 
 Terrain Rape 
Author Message
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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?


Tue Feb 08, 2011 6:47 am
Profile
User avatar

Joined: Wed Jan 07, 2009 10:26 am
Posts: 4074
Location: That quaint little British colony down south
Reply with quote
Post Re: Terrain Rape
Code:
function Update(self)
   if self:GetAltitude(0,5) < 1 then
      self.Sharpness = 1
   end
end


Tue Feb 08, 2011 7:09 am
Profile WWW
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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.


Tue Feb 08, 2011 7:30 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post 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.


Tue Feb 08, 2011 7:52 am
Profile WWW
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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.


Tue Feb 08, 2011 8:06 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post 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
That should be the working code, but I'm not sure if you're allowed to pass nil to a bunch of the arguments.

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.


Tue Feb 08, 2011 10:07 am
Profile WWW
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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(?)"?


Tue Feb 08, 2011 8:27 pm
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post 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.


Wed Feb 09, 2011 1:34 am
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Terrain Rape
Code:
true --wrap around the scene

Shouldn't that be SceneMan.Scene.WrapsX, to check if the scene actually wraps?


Wed Feb 09, 2011 2:06 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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?


Wed Feb 09, 2011 8:32 am
Profile
User avatar

Joined: Wed Jan 07, 2009 10:26 am
Posts: 4074
Location: That quaint little British colony down south
Reply with quote
Post 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.


Wed Feb 09, 2011 8:56 am
Profile WWW
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Terrain Rape
Yeah, I knew velocity was a vector but I didn't knew how to express it.


Wed Feb 09, 2011 9:01 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post 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 :P

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.


Wed Feb 09, 2011 11:03 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 13 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

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.154s | 14 Queries | GZIP : Off ]