Jump to content
  • Advertisement

Recommended Posts

I was wondering what are the possible ways to create a concept of attack speed in an OO-coded game such that the entity can only attack another entity after a certain delay from the previous attack?

Share this post


Link to post
Share on other sites
Advertisement
1 minute ago, Nypyren said:

currentTime >= nextAllowedAttackTime

Is it wise to add this field into a class like "warrior", or should this be handled somehow externally?

Share this post


Link to post
Share on other sites
8 hours ago, vinstap said:

Is it wise to add this field into a class like "warrior", or should this be handled somehow externally?

I would think the warrior's next time to attack would belong to the warrior, yes.

I would also not use absolute time since that makes things like time dilation and pausing annoying at best.

Share this post


Link to post
Share on other sites
17 hours ago, Satharis said:

I would also not use absolute time since that makes things like time dilation and pausing annoying at best.

Yeah.  In this case 'time' can be whatever measure of time is most appropriate for your game.  It could be number of frames (integer), simulation time in seconds (float), etc.

Share this post


Link to post
Share on other sites
On 3/11/2018 at 3:41 PM, Nypyren said:

currentTime >= nextAllowedAttackTime

Usually this is handled in the opposite direction.

  1. Set time until next attack is available.
    1. m_iMsUntilCanAttack = 1000000; // 1 second.
  2. Decrease value each frame.
    1. m_iMsUntilCanAttack -= iMicroSecondsThisFrame;
  3. Can attack if timer is 0 or below.
    1. bool CanAttack() const { return (m_iMsUntilCanAttack <= 0); }

Since 0 is always the boundary you don't have to keep track of a 2nd data point, and since you always check against the numeric literal 0 the code should be faster.


L. Spiro

Share this post


Link to post
Share on other sites
On 3/12/2018 at 2:50 AM, Satharis said:

I would think the warrior's next time to attack would belong to the warrior, yes.

I would also not use absolute time since that makes things like time dilation and pausing annoying at best.

Yea, you effectively want to negate all the time that accumulates when paused. I always use this psuedocode in my scripts when dealing with a pause invariant absolute time. It's useful to write as an abstract class so inheriting classes can easily access time.

float timePaused;
float totalTimePaused = 0f;
boolean paused;

GetTime(){
	if (paused){
		return timePaused - totalTimePaused;
	} else {
		return Time.fixedTime - totalTimePaused;
	}
}

PauseGame(){
	timePaused = Time.fixedTime;
}

UnPauseGame(){
	totalTimePaused += Time.fixedTime - timePaused;
}

 

Share this post


Link to post
Share on other sites
1 hour ago, samoan62 said:

Yea, you effectively want to negate all the time that accumulates when paused. I always use this psuedocode in my scripts when dealing with a pause invariant absolute time. It's useful to write as an abstract class so inheriting classes can easily access time.


float timePaused;
float totalTimePaused = 0f;
boolean paused;

GetTime(){
	if (paused){
		return timePaused - totalTimePaused;
	} else {
		return Time.fixedTime - totalTimePaused;
	}
}

PauseGame(){
	timePaused = Time.fixedTime;
}

UnPauseGame(){
	totalTimePaused += Time.fixedTime - timePaused;
}

 

This is not the way to implement pausing.

Your game timer should be a 64-bit integer that is incremented by a given number of microseconds each frame.  When paused, don't increment it.  This means you have 2 timers, as the system timer can't be paused (and is mainly used for visual effects, or a timer for anything that can't be paused).

In the context of an attack, the concept is the same: Don't update the timer if the game is paused.

As I mentioned, these timers tick down towards 0 and expire when TIME <= 0.  Since there will be many timers in the game for specific objects, the easiest way to avoid lots of special-case code and to reliably ensure that the whole scene pauses is to wrap the logical update in LogicUpdate( uint64_t _uiDelta ) or Tick( uint64_t _uiDelta ).  While the game is paused, pass 0 for _uiDelta, and every timer in the scene will behave as expected.


L. Spiro

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
  • Advertisement
  • Popular Tags

  • Similar Content

    • By Jemme
      Hello,
      I have built games in the past in unity and XNA, android SDK etc. but it’s always been quite specific, when building a small Game Engine or more accurately a sub-set of code that is reusable across projects the tendency to structure the project falls towards composition of objects that are more "generic" than toward inheritance-based models.
      For the Engine specific sub-systems, we have components such as a MeshInstance/Renderer that contains a Handle to a Mesh in a MeshLibary and a handle to a Material from the material library which in turn hold PSO data etc. We can also have Components such as SoundSorce, which are managed by an AudioSystem and contains the data to specify what sound, at what volume etc.
      These systems can be Set up and shut down from within the Engine/Game class such as:
      void Engine::Run() { if (Initialize()) { //Main loop call the systems //Dispatch Events } ShutDown(); } void Engine::Initialize() { //Init all sub-systems FileSystem.Init(); RenderSystem.Init(); PhysicsSystem.Init(); AudioSystem.Init(); WorldManager.Init(); //Creats Entities } void Engine::ShutDown() { //shutdown all sub-systems WorldManager.ShutDown(); AudioSystem.ShutDown(); PhysicsSystem.ShutDown(); RenderSystem.ShutDown(); FileSystem.ShutDown(); } But where does logic go? in smaller games like XNA or SFML you generally create some managers, let’s take the example of darkest dungeon.
      They have various managers like:
      Darkest Dungeon Manager Campaign Selection Manager Estate manager Party formation manager Town manager etc.. All the logic and systems to run the game are based within the managers, and objects contain scripts of data that are fed thorough the systems.
      In a small reusable code base how would you separate the logic from the engine, should like the smaller games all the managers just be shoved into the Engine Class even though that goes against a reusable data-driven framework? Should they just be stuck in a GameLogic system that's is initialized in the Engine Initialism function. And how do people tend to connect data scripts to the other various engine systems without causing too much game specific coupling. For example, you can use an Event System, but firing and event such as DAMAGED_BY_ZOMBIE and having the internal engine respond to that seems to break the separation from the low-high level of the engine system.
      Would be great to here some opinions from the community on this subject as it is quite a vital and potentially problem prone aspect of engine/game development.
      Thanks.
    • By Helgraves
      Hello!
      I am seeking a few team members to help me run some survival sandbox game servers through a 3rd party hosting site. My goal is to replace "official" servers in the sense that our servers offer the best experience for players of all types (not easy to do!). Why do I need a team for this? Because the game we are working with has far more potential than most people realize - it is my hope that I can bring a better ruleset to the table that focuses more on fun-factor than a genre label.
      My end-game goal is to run quite a few long-term small MRPG servers across multiple games/platforms (platforms of course based on availability of supported server hosting). Personally, I see multiplayer and co-op gamers gravitating towards a more personal experience with small, MRPG servers, as opposed to something like an MMORPG.
      Current Progress:
      Design Document
      Server Patch Notes
      A little about me:
      I took 6 years of high school and have zero college education Zero game/software development experience Hate math, can't code, also can't create any type of art assets Musician of almost 30 years Work on songwriting and music production in a metal band based in my region Only have hobbies for things I'm passionate about, have had some success professionally, with more to come Can I build a toaster, no, but I can tell you exactly how it should work without confusing you That being said, I have made a lot of progress this year on my own - and currently have one server up and running. I am at a point now where I need to construct a small team to help me get my other servers up and running, as well as adding/creating custom content. 
      Currently looking for:
      1-2 x Mod Developers 1 x Server Administrator You must have access to the game we are running our server on, as well as any other tools that are needed to get the job done (like Unreal 4 engine, software development tools, etc.)
      I am more than willing to provide information as requested for anyone interested!
      Thank you for your time,
      Helgraves
    • By Hashbrown
      Hopefully this is a simple question for some of you. I've managed to create a nice fly cam:


      ...but now I'd like to make a standard fps control. If I keep the y axis at 0, I don't fly up or down and I obviously move around at y0, but if I look down, my player slows down. Keep in mind, I'm using my own little engine btw.
      I'm guessing this has to do to the fact that my w,a,s,d forward vectors are calculated using the model matrix which also calculated XYZ rotation. Making a google search, I found this link, but it's an Unreal related question, and on top of that using their graphical blueprint whatever you call it. But it's pretty much the same question and (I'm guessing) possible answer.
      What I think I should do
      Should I make a completely different model matrix that ignores the X and Z axis which I can use for the player's movement? I'm a little confused in what I can do, and I can't find anything on Google that isn't THREE.js or Unity related.
      I'm pretty sure I have to disconnect the look controls from the movement controls. I'd like to be able to move towards where I'm looking without flying up or down, but at the same time be able to apply gravity at some point. But for now, I'd really like to solve that "look down move slow" issue. 
      Thanks all for your support. Below I'll share some of the code I wrote for the movement.
       
      // Controls flyCam(camSpeed) { if (Game.Input.Key.rightArrow.down) { Game.camera.translateX(camSpeed); } if (Game.Input.Key.leftArrow.down) { Game.camera.translateX(-camSpeed); } if (Game.Input.Key.upArrow.down) { Game.camera.translateY(-camSpeed); } if (Game.Input.Key.downArrow.down) { Game.camera.translateY(camSpeed); } Game.camera.transform.rotation.y += Game.Input.Mouse.delta.x * (200.0 / Game.Renderer.width/2) * Game.Time.step; Game.camera.transform.rotation.x += Game.Input.Mouse.delta.y * (200.0 / Game.Renderer.height/2) * Game.Time.step; } // TranslateXYZ translateX (speed) { this.transform.position.x += this.transform.right.x * speed * Game.Time.step; this.transform.position.y += this.transform.right.y * speed * Game.Time.step; this.transform.position.z += this.transform.right.z * speed * Game.Time.step; } translateY (speed) { this.transform.position.x += this.transform.up.x * speed * Game.Time.step; this.transform.position.y += this.transform.up.y * speed * Game.Time.step; this.transform.position.z += this.transform.up.z * speed * Game.Time.step; } translateZ (speed) { this.transform.position.x += this.transform.forward.x * speed * Game.Time.step; this.transform.position.y += this.transform.forward.y * speed * Game.Time.step; this.transform.position.z += this.transform.forward.z * speed * Game.Time.step; } // Model Matrix Mat4.translate(translation, this.position.x, this.position.y, this.position.z); Mat4.scale(scale, this.scale.x, this.scale.y, this.scale.z); Mat4.rotateX(rotateX, this.rotation.x); Mat4.rotateY(rotateY, this.rotation.y); Mat4.rotateZ(rotateZ, this.rotation.z); Mat4.mul(rotateXY, rotateY, rotateX); Mat4.mul(rotation, rotateXY, rotateZ); Mat4.mul(rotScale, rotation, scale); Mat4.mul(model, translation, rotScale); // Update Direction Mat4.transformVec4(this.forward, FWD, model); Mat4.transformVec4(this.up, UP, model); Mat4.transformVec4(this.right, RIGHT, model);  
    • By drcrack
      It is a combination of fundamental RPG elements and challenging, session-based MOBA elements. Having features such as creating your unique build, customizing your outfit and preparing synergic team compositions with friends, players can brave dangerous adventures or merciless arena fights against deadly creatures and skilled players alike.

      More info: https://zealrpg.com/about
    • By Gnollrunner
      I wanted to get some thoughts on player character collisions in MMOs for my project.   As I recall the original Everquest had them, however WoW didn’t. I also remember Age of Conan had them but I’m guessing they were done on the server which was highly annoying because you could collide with things that were unseen. I’m not sure how EQ did them but I don’t remember having this problem in EQ, but it was a long time ago.

      My general idea as to do player collisions on the client side. A collision would only affect a given clients player character as seem from that client. On the server, characters would pass right through each other.  This means that because of lag, two players might see different things during a collision or one may think there was a collision while the other doesn’t, but I figure that’s less annoying than colliding with something you can’t see and everything should resolve at some point.

      There is one more case which I can see being a bit problematic but I think there might be a solution (actually my friend suggested it).  Suppose two characters run to the same spot at the same time.  At the time they reached the spot it was unoccupied but once the server updates each other’s position, they both occupy the same space. In this case after the update, a force vector is applied to each character that tries to push them away from each other. The vector is applied by each client to its own player. So basically player to player collisions aren’t necessarily absolute.

      I was also thinking you could generalize this and allow players to push each other.  When two players collide their bounding capsule would be slightly smaller than the radius where the force vector would come into play. So if you stood next to another player and pushed he would move.  By the vector rules he is pushing back on you (or rather your own client is pushing) but since your movement vector could overcome the collision force vector, only he moves unless he decides to push back. You could add mass calculation to this, so larger characters could push around smaller characters more easily.

      Of course there are griefing aspects to this, but I was thinking I would handle that with a reputation/faction system. Any thoughts?


       
       

  • Advertisement
  • Popular Now

  • Forum Statistics

    • Total Topics
      631374
    • Total Posts
      2999661
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!