Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

267 Neutral

About BUnzaga

  • Rank
  1. BUnzaga

    Ammo.js Collision Separation

    Well I went with what I posted above, only instead of handling the callback during the collision iteration, I handle it afterward, because removing the rigidbody in the middle of iterating them was causing the browser to lock up   Here is what I ended up with for those of you who are interested in Ammo.js and this topic.  Please, if someone knows a better way, let me know.   Demo: https://goote.ch/d3a10e52808241ada183928d966fadd8.project (webGL).   Code: for(var key in AmmoUtil.collision){ if(AmmoUtil.collision.hasOwnProperty(key)){ AmmoUtil.collision[key].separated ++; } } var dp = this.dispatcher; for(var i = 0, ilen = dp.getNumManifolds(); i < ilen; i++){ var manifold = dp.getManifoldByIndexInternal(i); var num_contacts = manifold.getNumContacts(); if(num_contacts === 0){ continue; } var bodyA = AmmoUtil.rigidBodies[manifold.getBody0()]; var bodyB = AmmoUtil.rigidBodies[manifold.getBody1()]; for (var j = 0; j < num_contacts; j++){ var pt = manifold.getContactPoint(j); if(pt.getDistance() < 0.0){ var colID = bodyA.entity.id+"_"+bodyB.entity.id; if(AmmoUtil.collision[colID] === undefined){ pt.getPositionWorldOnA(pvec); pt.getPositionWorldOnB(pvec2); var normalOnB = pt.get_m_normalWorldOnB(); var pointOnA = new goo.Vector3(pvec.x(), pvec.y(), pvec.z()); var pointOnB = new goo.Vector3(pvec2.x(), pvec2.y(), pvec2.z()); var normalOnB = new goo.Vector3(normalOnB.x(), normalOnB.y(), normalOnB.z()); var info = { first:true, entityA:bodyA.entity, entityB:bodyB.entity, dataA:{other:bodyB.entity, pointA:pointOnA, pointB:pointOnB, normal:normalOnB}, dataB:{other:bodyA.entity, pointA:pointOnB, pointB:pointOnA, normal:normalOnB}}; AmmoUtil.collision[colID] = info; } AmmoUtil.collision[colID].separated = 0; break; } } } for(var key in AmmoUtil.collision){ if(AmmoUtil.collision.hasOwnProperty(key)){ if(true === AmmoUtil.collision[key].first){ AmmoUtil.collision[key].first = false; var entA = AmmoUtil.collision[key].entityA; if(entA){ var rbc = entA.getComponent('RigidBodyComponent'); if(rbc){ if(rbc.collisionBegin){ rbc.collisionBegin(AmmoUtil.collision[key].dataA); } } } var entB = AmmoUtil.collision[key].entityB; if(entB){ var rbc = entB.getComponent('RigidBodyComponent'); if(rbc){ if(rbc.collisionBegin){ rbc.collisionBegin(AmmoUtil.collision[key].dataB); } } } } else{ if(AmmoUtil.collision[key].separated > 1){ var entA = AmmoUtil.collision[key].entityA; var entB = AmmoUtil.collision[key].entityB; if(entA){ var rbc = entA.getComponent("RigidBodyComponent"); if(rbc){ if(rbc.collisionEnd){ rbc.collisionEnd(entB); } } } if(entB){ var rbc = entB.getComponent("RigidBodyComponent"); if(rbc){ if(rbc.collisionEnd){ rbc.collisionEnd(entA); } } } delete AmmoUtil.collision[key]; } } } }
  2. I'm using Ammo.js with the Goo webGL engine, and I'm working on trying to get triggers implemented, but I'm having some struggle finding a 'good' way to handle collision separation.   Here is a jsFiddle which shows how to handle collision starting:   http://jsfiddle.net/ajd7vd1o/   I'm also planning to implement a 'callback' type thing like this:   http://gamedev.stackexchange.com/questions/22442/how-get-collision-callback-of-two-specific-objects-using-bullet-physics   So when one object collides with another, it will pass in some collision info.   The problem I am having, is figuring out a good way to handle the separation, when the two previously colliding objects are no longer colliding.   Supposedly, there are gContactProcessed and gContactDestroyed callbacks which I could tap into, but I don't think these are currently possible.   http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Collision_Callbacks_and_Triggers   So I'm reaching out, before I start from scratch creating my own functionality, to see how other people have handled this.   Here is my main idea:   1. Have a map of collisions. 2. At the start of each pass, set a boolean value for all current collisions to false. 3. The fist time a collision is added to the map, trigger the onCollisionBegin callback, with the data from the collision. 4. During the collision check, if two objects are still colliding, set their boolean value to true. 5. For each collision in the map, if their boolean value is still false, trigger the onCollisionEnd callback and remove it from the map.   Does something like this seem good?  Are there any current implementations of Ammo.js with collision separation mechanics that I can look at?   Thank you in advance!
  3. BUnzaga

    'Fixed Timestep' wrap around problem

      I currently have implemented the first suggestion, but would like more information on how I would go about doing your second suggestion properly.  I don't expect you guys to do the work for me, but just a keyword or two to look up in google would be highly appreciated.   So in my demo, I have 'previous', 'current', and 'rendered'(a better word would be interpolated).  In your second idea, I would use the interpolated position AFTER the physics calculation, not DURING it.  I like how that sounds.  Something like...      while (accumulated >= TIC) {   interpolated = oldPos = newPos   newPos += TIC * Velocity   accumulated -= TIC  }  ticLeft = accumulated / TIC  smooth = 1.0 - ticLeft  interpolated = (newPos * ticLeft) + (oldPos * smooth) // handle the wrap around logic here? // if interpolated > screen extents, set interpolated & oldPos & newPos to the teleported position?
  4. BUnzaga

    'Fixed Timestep' wrap around problem

    Hey thank you for the reply Paradigm Shifter.  Yes I wanted a similar effect, such as in Asteroids, only I don't need it to show the remaining ship as it wraps.  Just a simple...  if > screen width, put back to 0.  The problem is that due to the interpolation, you can actually SEE the re-positioning, rather than it just appearing instantly on the other side.   In my fixed update, it just checks...   if arrowPos.x > screen width, set it to 0.  If arrowPos.x < 0 set it to screen width.   I am new to using an interpolation such as this, so I haven't had to deal with this sort of behavior before.   When the ship gets to the screen width, do I set ALL of them to 0?  Current Position, Previous Position, and Rendered(interpolated) Position?
  5. I've been working on a personal 2d HTML5 Canvas engine, and I am trying to implement Glenn Fiedlers fixed time step algorithm: http://gafferongames.com/game-physics/fix-your-timestep/   I have read through these other examples of how Box2D did it: http://www.unagames.com/blog/daniele/2010/06/fixed-time-step-implementation-box2d http://blog.allanbishop.com/box-2d-2-1a-tutorial-part-10-fixed-time-step/   The problem I am having is that objects don't wrap around the edges of the screen properly.   For example, if I have a scrolling background, and the position gets to greater than 800, and I want to wrap it back around to 0, you can see it visually moving there, rather than instantly appearing.   I am thinking, perhaps i don't know the proper way to implement this awesome algorithm.   Here is a basic pseudo code of what I am doing...   function update(){   // code to determine time passed, etc    while (accumulated >= TIC) {   resetSmooth();   fixedUpdate( TIC );   accumulated -= TIC;  }  ticLeft = accumulated / TIC;  render(ticLeft) }   function resetSmooth(){  renderPos = oldPos = currentPos; }   function fixedUpdate( dt ){  oldPos = currentPos;  currentPos += velocity; }   function render (ticLeft){  smooth = 1.0 - ticLeft;  renderPos = (currentPos * ticLeft) + (oldPos * smooth) }   The smoothing is awesome, but it is just the wrap around warping that I need help figuring out.  Also, in my collision detection  and what not, do I use currentPos, oldPos, or renderPos ?   Thank you for any help, and here is a quick demo of what I am talking about:   http://www.buff.bunzaga.com   It works in IE 10.0.4, Moz 20.0.1, and Chrome 26.0.1410.64 m
  6. I have a grid of nodes, which contain a list of neighbor nodes.  I wanted to create a FindPath function, with a Start position and a Goal position (both 3d Vectors, using X and Z, UP is 0).  I can easily get the nearest node to start, and the nearest node to goal, but I wanted to also make sure these nodes are in the direction the unit would be travelling.   For example, I don't want the unit to go AWAY from the goal, and then back track toward the goal, because the 'nearest' node to him was behind him.  I'll supply a picture to make more sense.     So in this picture, you can see the 'nearest' nodes to start and goal are where the red X's are.  Start is where the spider is located, and goal is where the black arrow is pointing.  You can see, the nearest start node, is actually in the other direction of the goal, where the yellow circled one is in the direction of the goal, even though it is further than the 'nearest' one.  The same goes for the nearest goal node.   I may be making this harder than it needs to be, but I can't seem to figure out the proper maths involved to get the nodes circled in yellow as 'start' and 'goal' nodes.   Here are the things I know:   startVector goalVector distanceFromStartToGoal   I need to use this information, while iterating throughout the list of nodes to determine:   startNode goalNode   While iterating, I can figure out:   nodeDistanceToGoal nodeDistanceToStart   So using all this information, I need to determine nearest node to startVector and the nearest node to goalVector, which are also in the direction from start to goal.   Any ideas?
  7. Thank you for the feedback guys.   I did want to do something like a rogue-like, so I'll check it out for sure.
  8. The game is meant to be developed for portable tablets, specifically the Android.  It is an RPG dungeon crawler style game, using 'rogue' like dungeon generation.   I am debating between two control schemes for mobile devices. 1. Taps and Swipes: Game mechanics, such as movement, attacks, etc would all be handled through tapping and swiping the screen. 2. DPad + Buttons: Movement and actions would be performed using a DPad icon in the lower left corner, and 2-4 buttons on the lower right corner.   The second opinion I am interested in is for overall gameplay. 1. Turn Based: The user would be able to move around the level freely, until combat begins, at which time combat would go into a turn based mode.  The enemies would have a turn to move and attack, then the user would have a turn to move and attack.  Initiative would be random. 2. Real Time Action: The user would be able to move freely around the level, combat would be handled in real time.  Basically, the user would enter a room and start hacking and slashing.   I would appreciate any feedback about these topics.  The engine I will be using is Unity3d.  Thank you in advance.
  9. Thanks slicer4ever, that is a good idea about setting them to null for error checking.
  10. In Javascript, if I know a variable type, but not necessarily the value, is it better on memory or run-time performance to instantiate it with a 'dummy' value, or is it better to just leave it undefined, and then only instantiate it when it is first needed? For example... var array1; var number1; var string1; /* vs */ var array2 = []; var number2 = 0.0; var string2 = ""; // later in code... function onInit(){ array1=[1,2,3]; array2=[1,2,3]; number1 = 3.142; number2 = 2.718; string1 = "Hello"; string2 = "World"; } Is it best to fill the variable with a dummy 'type' or just leave it 'undefined' ?
  11. slmgc, From what you are describing, it sounds like you are putting your actions into a queue or list of some sort, is that safe to assume? Then when you 'remove' or cancel the action, it removes only the one associated to that set or index. It is an interesting approach, it sort of turns duplicate actions into unique actions via your indexing (set) system. Thank you for sharing that with me.
  12. You had it right the first time nobodynews, it looks like the integer approach will be what I'll go with. Daaark, you hit the nail on the head with your example. Say I do have both a pen and a mouse attached (for some crazy reason). I want to be able to take either a pen movement or a mouse movement, and apply both to the same action, but when one stops, and the other does not, I need a way to determine that: 1. The pen stopped. 2. The mouse is still moving. 3. Reflect this within the game. By using nobodynews example, it would go something like... 1. Start moving mouse along the positive x axis, the mouse_px event will be triggered with a '1' value passed in (just as an example). 2. The px_axis_int will be incremented by +1. 3. Start moving pen or finger also along the positive x axis, the pen_px or finger_px event will be triggered with a '1' value passed in. 4. The px_axis_int will be incremented by +1 for the pen and or finger. Since all three of these actions 'mouse_px', 'pen_px', and 'finger_px' are tied to the same event... uh... 'move_right', lets say... dVal.x = 1.0 So now the character starts moving along the x axis. Now say I stop moving the mouse, I'll have to set px_axis_int -=1, then check if (px_axis_int == 0){dVal.x = 0.0}. I would do this for each input assigned to this action. Unless someone has a better way to accomplish this? Of course these are just obscure examples, but I just like to cover all my bases... Most people wouldn't assign 'W', 'Up Arrow', 'Right Mouse Button', 'Joystick Button 8', all to the same action, and use them interchangeably, but 'what if'? I just want a system that works for whatever the user wants to end up doing...
  13. I am trying to put together a thorough input system, and I can't seem to work it through in my head (or in code). Say for example, I want to use x number of keys, or mouse button(s) or joystick button(s) to perform a single continuous action, for example 'running forward'. I can handle gathering the input, and I can handle associating the event with an action, but what I can't figure out, is the best way to cross-check for the current state of the 'other' inputs. For discussion sake, lets say a key event would be something like... 'key_space', 'mouse_1', 'joy_1', followed by the appropriate data, such as 'true', 'false', .0121, etc. So say I bound 'key_w', 'key_up', as well as 'mouse_2' to the action 'forward'. So now if I press either of those keys, or the right mouse button, the 'forward' action will happen, meaning, the player will run 'forward'. So now say I press all three, this works fine, because they all do the same function. But what happens when I let go of the right mouse button? In code, it would send through a 'mouse_2' event with the data 'false', which should cause the player to stop moving forward, unfortunately, both key_w, and key_up, are still down... Is there any way to tackle something like this? Where I could have (n) number of inputs to handle a single thing like this? I know if I have a finite number of options, I could just check for the state of the keys when the 'up' event occurs... if(false == keys_w){/*stop*/}else{/*keep going*/} I thought of using an integer for this, but that just seems sloppy... Like if I press key_w, held_amt++, if I press key_up, held_amt++, if I press mouse_2, held_amt++. Then when I release one of them, I do held_amt--, check if it is equal to zero, and then if it is, stop running... I don't know, this just seems very sloppy to me. On top of this, say I pressed forward, then back, then a different forward key. I would want it to respond properly to the currently held down keys, all of which could be reassigned and the amounts of them could be 1 to n. Please help if you can! By the way, I have already read through http://www.gamedev.n...stem-for-games/ which was informative and helpful, but it doesn't cover my issue. I have also tried looking up anything I can find in google, as well as on these boards, but most of them have to do with the lower level logic of how to just get multiple sources of input, rather than the higher functionality of how to orchestrate it. EDIT: The only other method I was thinking of was polling the state of each potential input onUpdate, but I wanted use a callback system instead, onKeyChange... onKeyUp / onKeyDown type of thing.
  14. Brilliant, I hadn't thought of doing it that way. Thank you all for responding, by reading through these responses, I am starting to see the 'bigger picture'. ddn, I like that way of thinking: instance vs composition. I really do feel like the data driven way of doing things fits in well with my own mentality, and like PaloDeQueso said, I'll just have to stop thinking about it, and start working with it for it to truly become natural. Any other advice or insight is welcome!
  15. I have been programming for a few years now, self taught for the most part, and have been able to understand quite a bit on my own, but I am having a hard time wrapping my brain around a 'proper' data driven architecture for game development. For a while now, I have been sort of moving in a data driven direction, subconsciously, but have only now recognized it for what it is, and would like to learn more about it, and take full advantage of using a data driven approach. For example, say I am doing a tower defense game... From what I understand about the data driven approach, I would essentially have an array of entity ID's, which other tables would reference for the individual 'data' pertaining to each entity. I would then have methods which I would use to manipulate this data (separate from any 'Object')... What I don't understand... is what about the finer details? Like say I have a Poison Tower, which does AoE damage per tic. Then I have a basic Pea Shooter, which shoots a strait bullet at the 'oldest' creep x times per second. Finally lets say there is a Snare Tower, which will slow down creeps within a set radius around the tower. So obviously there is common 'data' between these towers, such as x/y position, active/inactive, radius of influence, price to purchase, price for upgrades, etc. This 'common' data could all be managed using the same methods, but what about the more uncommon information? Do I create a separate method for each individual tower type, or do I use a switch to determine the type, and handle the 'special conditions' within the main method? From an OOP approach, I would create a base Tower Object, and derive each new tower type from the parent, using overloaded functions, or adding additional functions if needed. To be more specific... When every tower is created, the user needs to decide on the X, Y position, probably with a mouse or finger. Every tower needs this, so it would go in the generic 'tower creation system'. When the user buys an upgrade, the data can be taken from the table, and it is the same for every tower. On the other hand, when it comes time to scan the oldest enemies in the towers radius of influence, and then deciding on if it should shoot a bullet, apply a poison, or reduce speed... is this handled by the same system, or should I create a separate system for each TYPE? What about in games where there are SEVERAL different types of enemies... Does each enemy type need its own 'system', or do I just make one big system, and use a switch to manipulate the data appropriately? I really like the data driven approach, and like I said, every time I would write individual onHoverBegin, onHoverEnd, onClick, etc for each button in my UI, I would always tell myself... "There has to be a better way for this". Now I realize a data driven system is exactly what I was looking for, now I just need a bit of help understanding it on a 'personal' level. Thank you in advance. Yes, I have used google, as well as the search field on this website, but if you can find something I missed, I am more than happy to check it out!
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!