Moving the player around without taking away control

Started by Satoh, December 06, 2017, 08:41:55 PM

Previous topic - Next topic
So, I find a lot of circumstances where I need to push or pull the player around, but I don't want them to lose the ability to push and pull in return...

That is, objects that suck the player toward them or push them away, or platforms that move around, but the player can always move around in conjunction with this other applied force.

I know this CAN be done by calling hero:set_position(...) in a timer, but as I've been finding multiple reasons to need to do this, I'm starting to think I should at least ask if I'm doing it the hard way and there actually is some way to multiply force vectors together on an existing movement or something... yknow, just literally anything other than continually hardcoding the hero's X and Y positions, which I'm led to believe is somewhat going against the 'intent' of solarus' movement system.

(I noticed that if I call a timer at 0ms interval, and move the hero 1 px each time, it only equates to about 60 px/s, as a hero walking at speed 60 will basically stand still under that force, using my method... but 0ms and 1px SHOULD be a force >1000px/s... interestingly enough this force does drastically decrease when set to 1ms interval, such that a player moving at speed 60 can easily walk right through it. This is the other reason I want a different 'better' method. I can't control the 'speed' in a logical way using timers and set_position... it just doesn't behave the way it logically should, given that 1 pixel every millisecond equals 1000px/s, and the timer system only seems to go as high as 60px/s.)
Patience is difficult and rarely thanked, but always appreciated, and sorely missed when absent.

For a platform, easy way: use the event on_position_changed to find all movable entities over the platform and move them. Note that you need to check the entities in the rectangle corresponding to the bounding box but before the platform had moved. Use test_obstacles to know if entities can be moved. Check the ground position, instead of the usual position, to know if entities are over the platform (at least for the hero, or you will have problems).

For enemies pushing the hero you need something different.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."