Push objects when walking into them

Hello,

I am wondering how I can move my object (chest) slightly whenever the player walks into it. Similar to the binding of isaac’s mechanics.

Thanks!

  • A

That’s part of collision resolution, instead of moving the player out of an object, you move the object until it isn’t colliding with the player.

@BurntPizza , but how could I achieve a bit of a sliding effect with it. Like you push it and it slides with a slight bit of resistance?

If you aren’t doing explicit physics, then you vary the balance from player is moved (immovable wall) to object is moving out of the way of the player (mass-less movable wall) over time (frames).
Start at immovable, over n frames interpolate to completely movable. As long as the player is still walking into the object, it accelerates. Over compensating the move-away simulates an elastic collision, i.e. a bouncy surface, whereas exactly matching the player is an inelastic collision.

The explicit phyisics are thus: http://www.physicsclassroom.com/calcpad/momentum
EDIT: I should add that if you do want realistic physics you should just use box2d or something. Save your time and sanity.

Can you please learn to Google things, or at least right am informative post?

Almost every post you are asking “how to do xyz” without any other information.

What have you tried? What do you have? Does what you have work but behave incorrectly?

This is a community for help, I get that. But hand holding is something else.

@Gibbo3771 Sorry, I didn’t see that you responded this here. I always Google before coming here, and attempt things on my own. Usually, I make a post then try and do it on my own, later checking on any responses I get.

I’ll just be sure to avoid posting here next time. Thanks.

Don’t avoid posting here, we’re here to help you. However as Gibbo said, many of your questions provide little context and seem to present no effort from your side. If you have a problem and you’ve tried to fix it yourself for at least a couple hours you can and should post here. But the majority of the learning process for programming in general is just trying things out yourself instead of relying on others. The difference between a great coder and an amateur is the amount of hand holding they require.

@Slyth2727 , thank you for addressing that. While I do post a lot of questions, I do attempt them. A majority of the time, I do spend an hour or so working on it. Believe it or not, I’m practically working on this project 24/7. I’ve found that I’m used to wanting to do something, then asking about it, then working on it while I wait for a reply. My real goal is too find the appropriate ways of doing things. The cleanest ways.

I’ve spent much more time on SO, java documentation, and libGDX documentation that I have here. I suppose I do need to add a bit more context. Sorry about that.

I should also add that I do search for all post here regarding my questions, but rarely find what I am looking for. In my latest case, I do not understand how to get mouse coordinates in a scaled setting. I’ll explain,

I have a tile map setup at the moment that is zoomed in. I’m using an orthographic camera at 15f and 9f viewport size. I need to also convert mouse position coordinates into this 1f unit system, so that I can appropriately find which tile I am clicking. I’m using this for a shooter game I’m working on when bored in my java class. My goal is too shoot towards it. I’ve tried to find the answer, and even made a make shift, non re-sizable, version - but I can’t find anything good.

Mouse coords transform is Camera.unproject()

The current top post on /r/ProgrammerHumor is somewhat relevant:

Reading how to do something is very rarely enough to solve a problem. Most of learning to program programming is guessing how something should work, trying it, inevitably breaking it, and after a few repeated cycles, getting the correct answer.

Unless you know what doesn’t work, you’re just going to run into the same problems later when you try something slightly different.

Thank you for introducing me to my new favorite sub on a bad day. I love you. I’m very emotional right now.

This almost never happens. Approximately 0% per cent of the time. At least not on the first, second or even eleventh attempt. And when you finally do get it just right - someone has already done it better. This will mostly always be 100% of the time.

At best you are doing premature optimization - which is very bad: http://c2.com/cgi/wiki?PrematureOptimization

At worst you’ll never get anything done.

On the other hand reinventing the wheel for your own amusement has its own merits but only with the expectation that you’ll probably do a piss poor job at it.