#1 2016-08-10 16:45:49

bobsimov
Member

Ammo System (similar to COD )

I managed to make an ammo system like quake games, but i am aiming for more realistic approach to ammo. Can anybody suggest a way or even provide code sinps ?

Offline

#2 2016-08-10 18:51:13

chasester
Member

Re: Ammo System (similar to COD )

You have to look at the math of guns. But the general idea is to

Gotto weapon.cpp (I think its the same name in tesseract)
find the function shoot(physent *d, vec at).

at is the direction you are firing in and d is the person firing (this fires for every person) for player1 (the control player aka the user) and bots controlled by the user firing this command this should do both the shoot commands the message to the server and the effects. For all other people this only does the effects.

So there are some major elements that sauer doesnt not take into account lets list them first then take a look at a way to add them:

  • Recoil- the feedback a gun gives when shot. This throws users aim off in a -y direction (torwards the camera)

  • Lateral movement - This is any movement from the player that moves left and right juctposition to the camera. This will cause -x +x movement on the aim target

  • Linear movement - this is walking forward and backwards, when walking realistically you are falling then catching your self then falling then catching your self. so this cause you to dip as you move, therefore we need to take into account +pitch and -pitch

  • Stress level - one of the biggest reasons trained people miss shots is due to stress, we should simply take into account the players health, or health loss over a period of time and make them "more desperate" with lower health. We could through some randomness in here and play around with some options. Other factor you could consider say if its one hit kill or close to one hit kill (like maybe 2 body shots 3 leg arm shots and one head shot) is how many bullets "Just Missed", this could add to a fear factor. If those threats that shot those bullets are still alive you could just add to your "fear" level and play with various ways to handle that. Also shooting faster could reduce aim, not only because of the recoil but because of the stress, you could do this by simply checking how many shoots hit, vs missed and then add a factor based on this. This would be something you want to customize based on the game player experience you want to provide

  • Key Factors - Things like fallling or jumpping, or landing, swimming, etc should play with players am, jump shooting people is not only cheap unrealistic , but also annoying to players getting shot. Realistically your aim is gonna be thrown off randomly in a +z direction with minor amounts in lateral and pitch factors, so simply throwing in some randomness on your shots when you shoot you can just simply fix any of these issues so they feel more realistic and less hacky.

So lets break this down:

Recoil

This is probably the most noticable of these in a realistic fps game. There are several key factors.

Kick strength - the amount of force the gun gives off from firing the bullet. This should be set on a per gun state inside of game.h guninfo. Which it already is so we dont need to modify this just look at the current value (maybe play with it a lil.

Player strength - if you have a stat system or multiple class system or somthing of that nature you will need to set this on a per player level. Otherwise use a constant. Take into account this should be player weight + muscule mass. So larger players should have more then skinner smaller players.

Muscle memmory - this is the concept that you have certian preprogram spots in your brain of how things should line up. Like how do you type with out looking at the keys or thinking about exactly where all the keys are (assuming you can do that). So this applies to aiming in that, you brain will try to bring the gun back to the spot that it left, over the matter of a few millisecond, if the gun fires fast, or there is a large amount of recoil then it will take longer to get this back to the origin spot (and may through off the origin spot slightly. So guns with quick shoot times should shoot more irratically if held down long. This is more of a game play factor and you should play with this idea, on a per weapon basis.

So the algorithm should read somthing like min(playerstrength - kickback , 0) meaning that we want a negitive number back, that is not above 0 beacuse if are player strength is larger then the kickback the gun should not move. Then we can take kick back and simply apply it over a couple frames, that way if the weapon fires again a small amount of kick back is retained. This makes it so that shooting in rappid succession will eventually throw off your aim. Giving the first few bullets perfect aim and then throwing off the aim over the next few.

Now this reciol will give us a fairly -y reaction, so we will just need to add that to the over all aim factor. We should add a lil -x and +x in there to so maybe run a random variable that addes very small amount of lattal movement.

Lateral movement

This is farely simple. If the player is strafing then we if(d->stafe != 0) offset.x += intensity *d->staff * d->vel.length().  wereas intensity is the amount you want this to effect the player. Bigger gun more intensity. This should basically use the same idea of player strength - gun wieght. heavier guns effect you more while moving.

Linnear movement

Same as above save we will look at just the move command and change the other axis. If(d-.move != 0) offset.y += intensity * d->move * d->vel.length();

For all the other ones you are either gonna add or remove from this vec offset.

vec at is the direction the camera is facing. d->o is the source of the player. so at.normalize() (which i do believe is already done) gives us a vector postion and a direction which is a ray (a source and a direction). now we need to modify this rays direction based on the cameras juctposition (meaning in camera space). Ill explain this simply and you can just look up projection and camera vs local space if you have questions. So You are in a world, there is a givin up down left and right forward and back. This is the global access where going east makes you go in the positive x west -x and so forth so on. Local space is based on the player or object and its facing location. So if i where to straft left this may add both x and y values. so we need to reset the aim after figuring out how it is effected in local space.

So to do this we must project the offeset vector in global space (right now its in camera space, where right is moving the vector right and left is moving the vector left).

vec offsetshootvector(vec at, vec offset, physent *d)
{
if(offset.iszero()) return at;
if(d->roll)offset.rotate_around_y(-d->roll*RAD);
if (d->pitch) offset.rotate_around_x(d->pitch*RAD);
if (d->yaw)offset.rotate_around_z(d->yaw*RAD);
offset.add(at);
offset.normalize();
return offset;
}

I think thats right. Iver not played with vectors in a while. If this gives you a wierd error ill look at it and see what I did wrong :).

chasester

Offline

#3 2016-08-11 07:05:24

bobsimov
Member

Re: Ammo System (similar to COD )

Thanks :) i did a system that is simpler , i made an ammo int and every time i shoot , -1 bullet , after it becomes zero , subtract 30 from total ammo and reset the ammo counter (30/250 becomes 30/220) But you explained a lot of important aspects pf such system . thanks ! Since TC: remastered is cancelled , i am working ona branch of Tesseract that is an open source FPS game . It will be open source :)

Offline

#4 2016-08-11 15:39:30

chasester
Member

Re: Ammo System (similar to COD )

I wrote a more oo version of this you may want to consider using a class based approach in the cass you want to make weapons that dont follow basic convention. Say a weapon that gives player health on hit, or can be fired once every 30 second and give a player buffs etc.

@ABOVE
i miss read i thought you said realistic guns, meaning the fill and flow my bad :)

Last edited by chasester (2016-08-11 15:40:10)

Offline

#5 2016-08-17 19:16:07

RaZgRiZ
Moderator

Re: Ammo System (similar to COD )

A little irrelevant, but either this forum has no PM function or I can't seem to find it. Anyway, @chasester, I noticed a reply of yours in the cube forums:

Cube Script is at best hacking, but its a good hack when used for binding keys, or calling basic interface like gui or simple command interfaces. If you try attaching more than necessary you just end up with a very big unmanageable mess, and a lot of coping and pasting code, and checking things that really just get annoying after a while. if(= numargs 1) [ ] if(= numargs 2) [ ] ect. its really just annoying tbh.

Would you care to provide some examples of code with which cubescript gave you trouble with? I'm merely curious so as to what you were trying to do to see whether it was you being unfamiliar with how to do it efficiently or rather a lack of predefined functionality from the collection of hardcoded commands forcing you to work your way around :)

Offline

#6 2016-08-17 21:31:57

chasester
Member

Re: Ammo System (similar to COD )

I know cube script very well (not as well as you obviously) but fairly well. Cube script lacks classes, type definitions, casting, type checking, function parameters (args dont count as parameters), etc

It lacks structure. You basically write functions and pray that all parameters are passed in by the user correctly, and that they passed enough arguments. All it is is basic macro pointing, which makes it fast but has a lot of problems that macros do, saying you have no clue what is coming in and so you have no security that what is coming out is a useful result. So it can be useful for simple script, to open doors or force sounds or do binding or do simple menu structure. But Say you want to program ai on how to behave or do complex gameplay checks, or write an entire game mode in cube script, its gonna be very messy because of the lack of needed structure.

also
if (= 5 5) //what the fuck it just looks weird
if(= 5 5) // throws an error unknow function if(

stupid stuff like that makes it annoying to program in and hard for new users to start using :)

Hense why i like angel script. It looks like c++ it acts like c++ and its probably just as fast as cube script. And it is an at run time like cube script (meaning you can change and reload script without leaving the program).

chasester

PS: sorrie i dont really have a particular example, and what ive seen from a lot of the stuff ppl wrote on the forums, you can get cube script to do about anything given the write COMMAND in line functions. Just its often very messy or unorganized or just plain hacky. Which is good if you are just trying to add one nominal feature but if you are writing an entire new game, you are gonna get pretty annoyed pretty fast.

Offline

#7 2016-08-18 08:59:11

RaZgRiZ
Moderator

Re: Ammo System (similar to COD )

I'm not really sure how the "structure" is an issue, because that seems to largely depend on one's coding style and how well the code in question is formatted. Lots of people write messy code because they are unfamiliar with CubeScript, or simply expect it to work the same way other languages do; for example people who have been using c++ and are used to putting ; after every single command. It's not messing anything up, but it's completely unnecessary.
Most of the time they're not very good at writing the code they want to make so they keep trying until something works, and then the chances of them attempting to improve said code to see why it really works or how to make it better are near none.
If you expect users unfamiliar with any given language to write beautiful/functional/efficient code, you have the wrong expectations :P

I do agree though that CubeScript's lack of type definitions bothers me. I also greatly enjoy the fact that it's not a necessary thing. Optimally I would like both to be possible, or in the very least not have to make my own type checks in cases where a very specific input is necessary (such as an IP parameter for a server func). I also wouldn't mind having "break" and "continue" so I could avoid working around them with ugly variables and checks. That has only happened once so far but given the complexity of the code and my lack of full understanding I wasn't sure I could factor it into something saner.

Safety concerns are also valid since a lot of code is globally accessible. It is a slight issue so long as a user can easily muck something up by running a simple command. In the case of CubeScript the motto is "stop trying to break things" when it comes to users interacting with the "external" layer of the code. Even people who have messed around with the code enough to be able to pull their own weight are still unfamiliar with the "local" command that restricts a variable inside the [] block it is defined. As such, they sometimes end up with a lot of variables that are unnecessarily global when they could technically not exist at all within a user's realm of influence. On the other hand there are also coders who like using variables so much they sometimes end up saving the same thing over and over under different names. These are hopeless cases and I don't look them in the eye :P

Much like constructors, my code usually has default parameters defined in place for when arguments are not defined. Sometimes they have limits, but in most cases they don't. Having checks everywhere to sanitize user input in a way that won't mess something up is, besides resource heavy, practically impossible to implement because users are unpredictable. You basically stop trying to make sure they pass sane values and hold them responsible for playing with your expensive toy; if you fuck it up, it's your problem, not mine.
Don't get me wrong though, I'm not saying that we don't have any kind of obligation to fool-proof code, I'm just saying that most of the time it's a waste of time to do so. There are some exceptions to the rule of course >_>

As for writing entire new games.. It can be done. It has been done :P Not at the complexity level of coding the entire backend of a game like tesseract's but simpler stuff like emulators and smaller games are definitely possible, although with the right COMMANDs I wouldn't call it impossible to do that either since it's basically access that we lack in order to code such things.
This reminds me, I need to make a mod thread to show off my thingies. It's about time I showed off a couple things :)

PS:

also
if (= 5 5) //what the fuck it just looks weird
if(= 5 5) // throws an error unknow function if(

CubeScript is picky about proper spacing much like C++ is picky about where you should put ; or not, that's not a valid argument point :P Besides, that's more of a personal opinion there, same as yours, but the if(= 5 5) instead looks weird to me.

Last edited by RaZgRiZ (2016-08-18 09:31:08)

Offline

#8 2016-08-18 15:59:06

chasester
Member

Re: Ammo System (similar to COD )

@cube script pickiness
Its like 5 lines of code to get rid of this error btw i did it once cuz it was strait up annoying. "(" "[" are not member variable characters so  they can just assume the end of the member varibles name when one comes up, kinda just lazy coding in my opinion.

@Cubestript structure
People like c++ cuz of its structure. Cube script is great for what its used for, an inline command and config scripting language. Just cuz it can do other things doesnt mean its good at other things. Global defines, and no type casting make it for me, A no sell when it comes to any kinda serious coding. It looks and feels to much like kitty script.

Closing thoughts
I dont disagree that cube script is "good" but any well written coding language is "good". But there are faster, more object oriented, more c++ looking coding languages out there that do a way better job at helping the user think in terms of a good object oriented design that are better suited for the engine. My project rival, I plan on keeping cube script as the config and basic command system, and using angelscript to control nodes and object behavior. Similarly I plan on rewriting parts of the menu system and using cubescript as the "html" and angel script as something similar to a css/java plug over top it. So the basic structure will be determined by the cube script code and the style, coloring, sizing etc will be determined by angelscript (along with any cool effects etc).

Chasester

Offline

#9 2016-08-18 16:39:20

RaZgRiZ
Moderator

Re: Ammo System (similar to COD )

chasester wrote:

@cube script pickiness
Its like 5 lines of code to get rid of this error btw i did it once cuz it was strait up annoying. "(" "[" are not member variable characters so  they can just assume the end of the member varibles name when one comes up, kinda just lazy coding in my opinion.

It has to do with the fact that a variable can be named anything

[ this is "lol

asdassaf^f3
] = 1

so when you do:

if(= 5 5) it assumes you're calling a var named if(= and it kinda breaks.

Offline

#10 2016-08-18 18:35:38

chasester
Member

Re: Ammo System (similar to COD )

ya but you cant name a varible abc(dk :P so it should just space it out for your abc ( dk :) thats what I basically did to fix it, and what most languages do. There are "name characters" (abc 123 etc) and there are operator characters (()[] etc). Its just odd how it sets up the token system that's all. Its an easy fix it just nv has been done which is odd. 0.0

@edit
also whats odd is you can do
(concat "blah" "blah") but if you go if( = 4 4 ) this thows an error? so it only counts ( in if it comes after a charater not if it comes before 0.0 again really wierd.

Last edited by chasester (2016-08-18 19:18:18)

Offline

#11 2016-08-18 20:44:35

RaZgRiZ
Moderator

Re: Ammo System (similar to COD )

chasester wrote:

ya but you cant name a varible abc(dk :P so it should just space it out for your abc ( dk :) thats what I basically did to fix it, and what most languages do. There are "name characters" (abc 123 etc) and there are operator characters (()[] etc). Its just odd how it sets up the token system that's all. Its an easy fix it just nv has been done which is odd. 0.0

@edit
also whats odd is you can do
(concat "blah" "blah") but if you go if( = 4 4 ) this thows an error? so it only counts ( in if it comes after a charater not if it comes before 0.0 again really wierd.


Sure you can:

"abc(dk" = 1

And yes, it is slightly weird, but it's a language quirk (fixable or not) that you would otherwise work around instead of trying to fix what's not exactly broken per se just because you can't handle spacing things like you're expected to :P

Offline

#12 2016-08-19 21:08:00

chasester
Member

Re: Ammo System (similar to COD )

RaZgRiZ wrote:
chasester wrote:

ya but you cant name a varible abc(dk :P so it should just space it out for your abc ( dk :) thats what I basically did to fix it, and what most languages do. There are "name characters" (abc 123 etc) and there are operator characters (()[] etc). Its just odd how it sets up the token system that's all. Its an easy fix it just nv has been done which is odd. 0.0

@edit
also whats odd is you can do
(concat "blah" "blah") but if you go if( = 4 4 ) this thows an error? so it only counts ( in if it comes after a charater not if it comes before 0.0 again really wierd.


Sure you can:

"abc(dk" = 1

And yes, it is slightly weird, but it's a language quirk (fixable or not) that you would otherwise work around instead of trying to fix what's not exactly broken per se just because you can't handle spacing things like you're expected to :P

No other language works like this. I think every one would just rather use normal naming conventions. No one wants a varible a(((P{}PIP{}a its just too much :P

Offline

#13 2016-08-19 21:52:03

RaZgRiZ
Moderator

Re: Ammo System (similar to COD )

chasester wrote:

No other language works like this. I think every one would just rather use normal naming conventions. No one wants a varible a(((P{}PIP{}a its just too much :P

It's true it's really unorthodox. Nobody really had any reason for this, but it came to be after I pestered eihrul about a weird bug I was having which turned out to be an @1 instead lf @l that I missed and that prompted him to prevent variables from starting with a number. It's just that it's possible, not that it's necessary.
Regardless, I'm also kinda thankful for that, since now vars like :bind:LCTRL can be safely used without chances to trigger errors. It's weird, but it helps me keep important vars away from people who might mess them up by accident since everything's global :)

Offline

#14 2016-08-20 19:47:34

chasester
Member

Re: Ammo System (similar to COD )

ya true I guess but seems like just letting ":" be the only one considered a "naming charater" and bannning the rest so not confuse the shit out every one would be a better implimentation. Seeing that most languages use :: as a namespace call so it could be used to make sudo namespaces :) Well not really but kinda ;)

Offline

Board footer