Author Topic: Moving the player around without taking away control  (Read 34 times)

Satoh

  • Newbie
  • *
  • Posts: 45
    • View Profile
Moving the player around without taking away control
« on: December 06, 2017, 08:41:55 pm »
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.)

Diarandor

  • Hero Member
  • *****
  • Posts: 805
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Moving the player around without taking away control
« Reply #1 on: December 06, 2017, 10:27:55 pm »
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.