Author Topic: How do you give an object a velocity without moving it? (odd problem)  (Read 2173 times)

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
It is an odd question, but here is the situation.

Essentially, I created platforms that the player can use to ride between two points. The player and other objects collide with these platforms normally, but if the player stands still while on a moving platform then he doesn't seem to collide with other platforms or fixed objects.

The game thinks the player's velocity is 0 even though he is being moved by the platform. I need the game to think he is moving so it will check for collisions, but without actually moving him because it would mess up the ride on the platform.

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
This seems to be related to colVector.x in some fashion.

I tried setting the player's colVector.x equal to the platforms, which makes the collisions work against some stationary objects (but not others strangely), but the collisions with mobile fixed objects are still sketchy at best.

It seems like colVector.x might be getting recalculated elsewhere which is preventing collisions.

Unfortunately, this screws up collisions with other mobile non-fixed objects while standing on the platform.
« Last Edit: Sun, Mar 22, 2015 by Minverva »

jester-race

  • Member
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
I haven't worked with Flash/Flixel in some time, but I seem to remember that Flixel's collision only handles one collision at a time.  I wonder if you'd be able to get around this by having a separate collider on the player that ignores collision with the moving platform, but not with static parts of the level.  Or if you need the second collider to also detect moving platforms, make the collider a bit shorter and raised up a bit so that it doesn't touch the platform you're riding.  Does that make any sense?

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
I haven't worked with Flash/Flixel in some time, but I seem to remember that Flixel's collision only handles one collision at a time.  I wonder if you'd be able to get around this by having a separate collider on the player that ignores collision with the moving platform, but not with static parts of the level.  Or if you need the second collider to also detect moving platforms, make the collider a bit shorter and raised up a bit so that it doesn't touch the platform you're riding.  Does that make any sense?

Well, since then I've designed my levels in a way that this bug doesn't matter. It is still very strange though. It seems like the bug might be based on the platforms changing their velocities which messes up the collision detection, because collisions I thought wouldn't get detected are working when the platforms aren't going back and forth and when they aren't near their end points (they slow down before stopping).

The "single collision" explanation is interesting. I've noticed that flixel has trouble with collisions when the velocities are high. Another easy way to mess up collisions, which I've used intentionally, is to call the update function of an object multiple times.

Sorry if I'm being a bit TL;DR so far. I'm not sure what you mean by adding a separate collider, but if there is some way to improve collision detection for the player then I'm certainly all ears.

PRIZZA

  • Member
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Does the player sprite just not collide with objects when it's riding on top of the moving platform? Does it, say, go right into a wall or something like that?

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
Well, it does collide with objects, but there seems to be situations where it doesn't. If I have the platforms move flush against a FlxTileBlock, the player on the platform won't collide with the tileblock and will instead overlap it slightly (hurts the player). I basically designed levels to avoid that situation.

I think this might be related to the platforms slowing down before stopping which messes up the collision boxes. None of these problems occur when the player is moving while on the platform.