• 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
P0jahn

Pushing objects

10 posts in this topic

In a 2D game, I want to being able to push other objects. 

Take into account that objects that you push can be a movable object.


I have already created a method that works but its not pretty and results ingame are not smooth.

0

Share this post


Link to post
Share on other sites

You want to provide more details and information.  In short all we can do right now is say "When the two objects are touching have them move together".  You might also want to take weight into account and slow down the movements to simulate the first object struggling to move the second.

0

Share this post


Link to post
Share on other sites
This quickly becomes pretty complex if you have multiple objects, where you can push an object which pushes another object and so forth. You're verging into full physics library territory here, so I would recommend you look into using an existing 2D physics library such as Box2D or Squirrel. Hooking up to these libraries is very easy, and they provide decently robust physics under a free license.
0

Share this post


Link to post
Share on other sites

You want to provide more details and information.  In short all we can do right now is say "When the two objects are touching have them move together".  You might also want to take weight into account and slow down the movements to simulate the first object struggling to move the second.

So say A is pushing B. If A is coming from the left, upon collision it will push B to the right.

If A is coming from above, it will push B downwards.

 

This quickly becomes pretty complex if you have multiple objects, where you can push an object which pushes another object and so forth. You're verging into full physics library territory here, so I would recommend you look into using an existing 2D physics library such as Box2D or Squirrel. Hooking up to these libraries is very easy, and they provide decently robust physics under a free license.

My game is not going to support multiple objects pushing each other. Integrating my game with a 2D physics library is just to much work for such small game. It would be like putting a 500 horse power engine in a piece of junk from the seventies.

1

Share this post


Link to post
Share on other sites

My game is not going to support multiple objects pushing each other. Integrating my game with a 2D physics library is just to much work for such small game. It would be like putting a 500 horse power engine in a piece of junk from the seventies.

 

I think you overestimate the difficulty and complexity of integrating a 2D physics lib. Seriously, take a look at the Box2D tutorials. It really isn't all that difficult.

1

Share this post


Link to post
Share on other sites

You want to provide more details and information.  In short all we can do right now is say "When the two objects are touching have them move together".  You might also want to take weight into account and slow down the movements to simulate the first object struggling to move the second.

So say A is pushing B. If A is coming from the left, upon collision it will push B to the right.

If A is coming from above, it will push B downwards.

 

Without counting physics into the mix yes it's that simple.  I was trying to point out that your post is to vague to hold a real discussion about.  We don't know what the problem is, we don't know what you did.  With lack of any relevant information all we can do is guess that you don't know how to detect the collision?  You can't figure out how to translate two objects at once?  What's not smooth, have you somehow poorly calculated the movements resulting in frame loss?  Are you unsure on how to apply the same movement vectors to the objects?

 

In short what I was getting at is don't be so vague.  Tell us what language you are using, what engine you are using what is happening and what the expected result was supposed to be.

2

Share this post


Link to post
Share on other sites

You have collision detection, right? From there on, follow these steps:

 

  1. Find out where player is in relation to the object. If player.y < object.y (assuming origin is on the top-left corner of the screen), then player is above the object. If player.x < object.x, then player is to the left of the object, and so on.
  2. Then, you need to determine when the 'push' happen. You need to figure this out yourself as each game is different.  You need some sort of trigger, when the push happens.  Does keep pressing the object will trigger the push?  What many seconds of pressing the d-pad till it triggers the push?  Or, do you need to press the button while close to the object to trigger the push? Does the player need a special 'push' animation?
  3. Once player is inside 'push' state, then you need to figure out how far is the push.  Different games do it differently.  Does each push pushes the object one tile away? Half a tile? Pixel-perfect push?

So yes, something as small as pushing objects still needs extensive thoughts and planning.

 

Happy coding!
 

1

Share this post


Link to post
Share on other sites

If your physics is really basic (like the physics in the games I'm writing now is) this may help.  By really basic I mean no terrain resistance or anything to affect the interaction of the 2 things outside of the motion of the first thing.  From your description of what you're looking for that may be the case.

 

I give each object a collisionRank parameter.  When my collision detector notices that 2 objects have overlapped, it passes them to a collision resolution function.  The collision resolution function looks at the collisionRank parameters of the 2 objects and resolves the overlap by moving the one with the lowest collisionRank.  If the object that got hit had the lower rank then it moves, effectively being pushed.

 

For what its worth, though, this method gives the same smoothness to the push as I get out of how I move the first object in the first place.  Any lack of smoothness comes from a bad timer function or browser portability (I'm coding in javascript) rather than the collision resolution.

 

Of course, this doesn't take into account any of the more complex issues that could arise, like the object having a resistance to being pushed, or what happens when one object pushes a second object into a 3rd object that has a higher collisionRank than the 1st object (or the 2nd object, for that matter).  Or, as noted above, whether you want there to be a trigger needed to cause the push to be possible in the first place.

 

Outside of something like that, as these other folks (who are way more experienced than I am) have pointed out, they'd need to know some sort of information about how you're handling your collision detection and resolution. 

0

Share this post


Link to post
Share on other sites

...so I would recommend you look into using an existing 2D physics library such as Box2D or Squirrel.

 

Just to clarify, it's chipmunk physics engine, not squirrel smile.png

Edited by BeerNutts
1

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