• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
BUnzaga

'Fixed Timestep' wrap around problem

6 posts in this topic

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 ? biggrin.png

 

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

Edited by BUnzaga
0

Share this post


Link to post
Share on other sites

You need to set the position to the new location without changing the velocity. Dunno if that would cause problems with the physics though, since the object basically "teleports" to a new position...

 

If you want to see an object which straddles the edges when it wraps around the screen (like the ship in asteroids) you can do that by having 4 objects placed at the corners of the screen distance apart that move in tandem (that way you get to see half of the ship on each side of the screen while it is moving off the edges). Objects which are more than one screen size distance away from the edge of the screen need to be repositioned so they are less than one screen distance away though, using the same method as above.

Edited by Paradigm Shifter
2

Share this post


Link to post
Share on other sites

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?

Edited by BUnzaga
0

Share this post


Link to post
Share on other sites

If you don't care about showing part of the ship on the other side, you can simply test the ship position with each edge and then teleport both the new position and the old one to the other side of the screen. In this way the ship seem to enter from the edge. Alternatively you can implement the wraparound logic after the interpolation step, i.e. storing an "absolute" ship position and then computing the modulus when computing the ship position on the screen. 

Edited by apatriarca
1

Share this post


Link to post
Share on other sites

....teleport both the new position and the old one to the other side of the screen. In this way the ship seem to enter from the edge. Alternatively you can implement the wraparound logic after the interpolation step, i.e. storing an "absolute" ship position and then computing the modulus when computing the ship position on the screen

 

I currently have implemented the first suggestion, but would like more information on how I would go about doing your second suggestion properly. biggrin.png  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?
Edited by BUnzaga
0

Share this post


Link to post
Share on other sites

The alternative suggested is keep all world coordinates in absolute terms (i.e. don't wrap them around by teleporting the ship), but then when it comes to drawing the ship map the coordinates into the screen width/height range using the modulo operator or fmodf.

 

Problem with that method is keeping the other objects near to the player so the collisions etc. still work.

0

Share this post


Link to post
Share on other sites

It's the wraparoud logic itself which complicates collision detection. I don't think the use of absolute coordinates adds much more complexity than managing several copies of each object. I have however to admit I have never implement an asteroid close using this strategy. The use of several copies is necessary* if one want to show parts of the object on the other side.

 

* when using shaders is probably possible to pass the absolute position and then create the different copies on the GPU but I'm not sure if it's worth the effort.

0

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
Sign in to follow this  
Followers 0