View Full Version : General code explained
2nd Nov 2001, 04:12 AM
I've decided to try and make a gun that fires projectiles that when it hits a pawn, they increase slightly in fatness.
Then at a certain point they explode. :D
auto state Flying
function ProcessTouch (Actor Other, vector HitLocation)
If ( (Other!=Instigator) && (!Other.IsA('Projectile') || (Other.CollisionRadius > 0)) )
Velocity = vector(Rotation) * speed;
Now the above code is from ShockProj, which is the altfire of the Shock Rifle.
Now the questions. :D
1) What's that auto doing infront of the state?
2) What's the differance between a processtouch and a touch?
3) What exactly is going on here? This is what I thought.
If the actor hit is not the firer and the actor is a projectile or the actor has a collision radius of none then Explode.
Is this correct?
4) If the above is correct then how does it tell if it's hit any walls or other players?
5)When does the function BeginState get called?
2nd Nov 2001, 07:03 AM
1) Objects will begin in this state if InitialState is not set.
2) ProcessTouch() is called from Touch() (defined in Projectile).
3) If actor hit is not the firer and is NOT a projectile or has a collision radius GREATER THAN zero, then explode.
4) When it hits a wall, HitWall() is called, which then calls Explode(). ShockProjs don't need to know if it hits a player.
5) I believe it's called as it enters the state. So if you call someObject.GotoState('Flying'), BeginState() for that state is immediately called.
2nd Nov 2001, 09:00 AM
1) How would you set the intial state otherwise?
2) I think I see. So processtouch is just the projectile version of touch?
3) Gotha. I was confused by the ! infront of the Other. :rolleyes:
4) Doesn't need to know because the processtouch sorts everything out.
5) Instead of putting the beginstate(), couldn't they just put the code at the top?
Extra question. :D
6) I think I remember seeing that case doesn't matter. But I notice that everyone is writing like, ProcessTouch.
Would Uscript see these two functions as the same?
2nd Nov 2001, 10:38 AM
1. GotoState('NameOfState'); //remember the single quotes around stateName
2,4) Well I will go into a little more detail on Touch for projectiles. Touch is written in the projectile class, and is inherited by all the children of Projectile. All projectiles use the same touch, and there is no need to override it.
When a projectile touches something it does basically two things, determine if it hits a Wall (part of the map), or something else like a player, another projectile, or whatever. When the projectile hits a Wall HitWall(...) is called by Touch, and you put whatever you want to happen to the projectile when it hits a wall in this function in your class. You can do many things in hitwall such as make it explode, bounce off, or what not.
If it hits something that is not a wall ProcessTouch(...) is called by Touch, so when you write ProcessTouch(...) in your class you do whatever you need to do to the object that it hit. So if it hit a pawn, it deals damge, whatever.
5. No you can't put it at the top since, ProcessTouch is not called till it hits an object. BeginState() called when the projectile starts to fly there the air. This sets the velocity of the projectile so that the projectile basicly goes the right way, and at the right angle. Its no good to have a missile flying sideways there the air.
6. It does not really matter how you type the function or variable names in UnrealScript since it is not Case Sensitive like some other languages. In unrealscript Function, function, and FuNcTiOn are the same thing. It all a matter of how easy you want to be able to read it. Captializing the first letter in each work helps, so you dont have to search for the beginning of the next word.
2nd Nov 2001, 02:42 PM
About capitalization, UScript doesn't care about it, but it's always a good idea (especially if you intend to learn other languages such as Java) to get used to using proper captialization.
3rd Nov 2001, 03:18 AM
Ah yes I see. :D
But on the note about Touch. You mentioned that it is written in the Projectile class.
Is the Pawn class written differantly in terms of the Touch function?
3rd Nov 2001, 07:34 AM
Yes, but you should check out these things yourself. Export the scripts from UnrealEd, open them in your favorite text editor, and search for the functions you are interested in. If a function is not defined in a class, it uses the version inherited from its superclass (parent class).
3rd Nov 2001, 10:30 AM
I was checking incase somebody knew the answer off hand.
It's not worth me looking all day through lots of classes if somebody here already knows it.
3rd Nov 2001, 11:36 AM
Yes it is. The best thing you can learn is to find code in all the stuff of UT. Well, it's good at least.
3rd Nov 2001, 01:57 PM
I once started as a complete n00b in UnrealScript(I didn't have any experience with UnrealScript's syntax, only Pascal and Delphi's syntax) but because I looked trough all the code searching for explinations I learned the hierachy of UnrealScript''s objects and learned a lot about having a nice style of writing your code. I really would recommend you looking trough code first and then asking instead of asking if someone knows it first.
4th Nov 2001, 04:38 AM
I wasn't debating that it's not a good thing to study Epic's code but I thought I asked a pretty simple question that could of been easily answered.
I've learnt alot over the passing days, more then I ever could of learnt staring confuzzled at Epics code but I certainly did not expect an ear bashing for asking questions.
I thought the forum was for asking questions and if somebody happened to knew the question off the top of there head they would answer. :(
4th Nov 2001, 05:09 AM
hohoho I don't have a single problem with you asking questions :) it was just a suggestion on how I learned how to code. I saw you posting a lot on this forum and that's good too becuase you are quickly learning things by asking them in the forums instead of figuring it out yourself. I really did not mean to hurt you :)
4th Nov 2001, 05:51 AM
I looked in the pawn class and did not find any function called Touch at all. :(
4th Nov 2001, 10:15 AM
Well, then it simply uses the version inherited from Actor, which does nothing.
5th Nov 2001, 04:16 AM
Then how does it detect when pawns touch it?
5th Nov 2001, 11:32 AM
Bots use Bump(). Not sure about the difference between this and Touch(). I wouldn't worry too much about it, unless you need to write new bot AI or something.
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.