Pixel-Based Movement

Post Reply
Mike Bullet
Posts: 5
Joined: Fri May 31, 2013 12:24 am

Pixel-Based Movement

Post by Mike Bullet »

I've got everything figured out - except, how would I setup pixel-based movement? I'm not talking about movement through the use of forces, but rather, constant velocity, infinite acceleration-type movement? Similar to an RPG-type character. Where I'd say "currently walking right, so move at 0.2 pixels per second".

I'm basically creating an Action RPG, and I'd like characters to walk like a standard 2D JRPG, but still able to be hit by monsters and have the character be pushed in a certain directions, and be able to push up against objects pushing them away.

Thanks!
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Pixel-Based Movement

Post by Basroil »

Sounds like you're over-complicating what could just be very simple stuff. Ignore actual simulation, just use the collision detection if needed, though if you do it the jrpg way even that isn't really needed.

Since it sounds like you are going for the 8bit style, why not just check every screen update or two if the edge pixels are in contact with other edge pixels, and if they are do some action. Definitely will reduce overhead, though will change the way you code enemies and levels.
Mike Bullet
Posts: 5
Joined: Fri May 31, 2013 12:24 am

Re: Pixel-Based Movement

Post by Mike Bullet »

That's how things are working now. I'd like to add some more complex physics systems. For example, being able to grab rocks and throw them. Or have enemies push you. Or have forces change. So many possibilities. I'm not making a JRPG per-say, I'm just trying to give it as an example of what I'd like to achieve.
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Pixel-Based Movement

Post by Basroil »

I based my comment on playing way too many old school games. In things like Zelda and Pokemon, you can interact with the environment and enemies to a certain extent, and your character can get bounced around pretty well without using "real" physics. On a 2d plane, it's pretty straight forward to make projectiles and the like, I remember using and making (mostly using :D ) calculator games that ran reasonably fast with a large set of collision effects. No sense in throwing away everything you already did if it isn't broken.

If you want to keep full physics without acceleration issues while moving, you'll need to use very large accelerations, but that might also override forces from other interactions. Fine if your character is a tank, not so much if you are made of styrofoam. You'll probably still want to go kinematic bodies with custom contact callbacks or keep reasonable acceleration lag (which often makes games harder as a bonus)
kyles
Posts: 1
Joined: Fri May 31, 2013 12:17 pm

Re: Pixel-Based Movement

Post by kyles »

You can check the velocity each step and apply a small impulse if it falls below your threshold. I've done this to achieve something similar to your scenario and it worked pretty well for me.
Mike Bullet
Posts: 5
Joined: Fri May 31, 2013 12:24 am

Re: Pixel-Based Movement

Post by Mike Bullet »

Basroil wrote:I based my comment on playing way too many old school games. In things like Zelda and Pokemon, you can interact with the environment and enemies to a certain extent, and your character can get bounced around pretty well without using "real" physics. On a 2d plane, it's pretty straight forward to make projectiles and the like, I remember using and making (mostly using :D ) calculator games that ran reasonably fast with a large set of collision effects. No sense in throwing away everything you already did if it isn't broken.
Yep of course. However, things are a bit more complicating than that. I'm working on a generic engine, and need to support more "physics". People've complained for a while, and I'd really like to get something going that they can appreciate.
Basroil wrote:If you want to keep full physics without acceleration issues while moving, you'll need to use very large accelerations, but that might also override forces from other interactions. Fine if your character is a tank, not so much if you are made of styrofoam. You'll probably still want to go kinematic bodies with custom contact callbacks or keep reasonable acceleration lag (which often makes games harder as a bonus)
Yeah, I thought about the very high accelerations - but as you pointed out, I'd turn into a tank and destroy everything in my path. The idea of special collision callbacks sound interesting though. Are you saying that I could set things up so the collision callback could dampen the impact virtually?
kyles wrote:You can check the velocity each step and apply a small impulse if it falls below your threshold. I've done this to achieve something similar to your scenario and it worked pretty well for me.
Are you saying that I can keep applying small instant impluses, and get instant acceleration? If so, how would I go about doing it that way?

Thank you everyone so far for the feedback, it's making me think!
STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Re: Pixel-Based Movement

Post by STTrife »

You could just set the desired velocity of an object in a the post-tick call back? or the pre-tick callback rather.. I dunno one of those :) Then you have what you call 'instant acceleration', but it should be called 'instant velocity' instead I think.
I believe that can work. Correct me if i'm wrong.
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Pixel-Based Movement

Post by Basroil »

STTrife wrote:but it should be called 'instant velocity' instead I think.
I believe that can work. Correct me if i'm wrong.
Yup, it is technically velocity, and a perfectly good way to do it is though calls like in the motor control (dynamic control) demo. Just replace the joint angle with a velocity. Problem still goes back to how high a value you need to move the character at the speed you want, and whether that will end up causing unintended side effects.
Mike Bullet
Posts: 5
Joined: Fri May 31, 2013 12:24 am

Re: Pixel-Based Movement

Post by Mike Bullet »

Basroil wrote:Problem still goes back to how high a value you need to move the character at the speed you want, and whether that will end up causing unintended side effects.
Yeah, this is the very thing I'm asking about. My original suggestion included just giving it intense accelerations to simulate velocities. The problem mentioned by yourself would be the tank issue since your impulses would be so massive.

Which is all understandable - trying to simulate something using unique system of physics is asking for trouble.

But out of curiosity, is there any way to respond to a callback and dampen the force applied to another object, so it can provide a movement force like a human's normal acceleration, but have the ability to push things instantaneously?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Pixel-Based Movement

Post by Basroil »

Mike Bullet wrote:
Basroil wrote: But out of curiosity, is there any way to respond to a callback and dampen the force applied to another object, so it can provide a movement force like a human's normal acceleration, but have the ability to push things instantaneously?
Sure is, but you might as well just make at least the character a kinematic body if that's your need. Doing that means you can change the "physics" of the character without worrying about mass. With that you can simply apply a velocity directly. For example, pressing forward gives you +1 forward speed, getting shot by an arrow to the knee means -.5 forward for a specific time, giving you an end result of 0.5 forward speed if you pressed forward, or -0.5 if you didn't. Makes you need to add collision characteristics for every type, but it's probably going to be easier than dealing with masses and impulses.
STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Re: Pixel-Based Movement

Post by STTrife »

I'ts kinda hard because on the one hand you say you want things to interact normally using the rules of physics, but on the other hand you want to be able to push things like rocks (thinking zelda like) instantly without slowing down your character right?
That sounds like two different things, which might be best solved with two different systems. So I do think that for your character you can go either with kinematic or rigidbody still, but the rocks you push instantly should be manually programmed (I would think you also make them kinematic bodies and update manually based on your own pixel based logic.. but then again it's 3d so it becomes hard to do that), and the stuff that follows normal physics rules could be rigidbodies in Bullet.
So I think it's not just about how you program your character, but also how you program the other objects in the game.
Maybe some example would help... for example what would happen if you push a rock (instantly) and something physical is stuck between the rock and the wall... you should watch out for just update positions and velocities then cause it will make the physical object fly away or something bad like that. A solution could be to do a collision check before you update position, so that you are not placing your character (or other instantly moving object) colliding with a physical object.
Mike Bullet
Posts: 5
Joined: Fri May 31, 2013 12:24 am

Re: Pixel-Based Movement

Post by Mike Bullet »

Yeah - you're absolutely right. I realized that pretty much last night when I was reognizing my current "pseudo-physics" code. So much is relying on unrealistic physics that just make standard gameplay.

I think my plan moving forward is just using the collision detection system provided by bullet, with the data that will inform me about collision points and normal, and apply that to my pseudo-physics. That way, I can continue to fully control all my actors, and deal with the specific collision cases of instantaneous movement against a standard accelerated moved object - like the rock hitting a physics object.

So to confirm - I could just use the collision detection system from bullet, right? And it can provide me information about collision points/normals so that I can make my own simulations, right?
STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Re: Pixel-Based Movement

Post by STTrife »

yeah absolutely, the collision system is separated from the dynamics system, so you can just add collision objects to your world, and check for collisions. However I did notice this way of working is not really that 'supported' out of the box. You can go either with

-collision callbacks
-iterating over all collision pairs
-using ghosts object with pair memory (but you still need to call the near-phase collision detection manually for some reason).

At least this is what I know about it. Someone who knows more about can probably tell you which way is wisest.
Post Reply