Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. We are looking for your feedback about Templates! Tell us about your experiences by taking our survey.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Building 2D platformer movement that can do (fake?) physics

Discussion in '2D' started by shellyalon, Dec 7, 2017.

  1. shellyalon


    Mar 26, 2013
    Hi everyone,
    i'm starting a new project and this time it will be a bit bigger: I am going to do a co-op game, where each player plays a magnet (one blue, one red) and with their magnetic powers they have to solve puzzles. Inspired by Snipperclips and other puzzle-platformers.

    The problem is building a framework for movement, on which I can build on. Obviously the default physics system is too messy and unreliable. But using only velocity makes it hard to accomodate for physics. Players should be affected/pushed/pulled by magnets/effectors (custom ones okay, too). They should also be able to push simple crates etc ...

    Right now I've build an okay-ish system that works like this. I've got a few different vectors that are being processed:
    • Movement vector from input
    • Custom gravity vector
    • Incoming magnetic forces (from other magnets)
    • other special stuff
    Then I add all those together (any maybe modify them a bit) and then just apply this vector to the velocity of the rigidbody. Since I do want the player to be able to interact with other (physics-rigidbody-based) objects in the scene, the character's rigidbody is not set to kinematic and has mass and stuff.

    This method works okay. It has it's downsides. For example I have to write any special behaviourss on the player that would be very easy to do with effectors. And the system is not full proof yet: the collisions aren't working perfectly yet.

    Now I wonder if there is a far better way to do it? For example a raycast-based collision system. I've looked at tutorials and the prime31 character controller, but I couldn't figure out if it's possible to combine it with physics.
    The player is supposed to interact with physics objects (push boxes) and be affected by forces (can be done the way I did it). For example it should have a weight and weigh down on platform etc.

    I don't have a real question I guess. Should I implant ray-based collision? How would one push boxes with this system? Would I need to manually addforce on the box on collision somehow?

    I'd just like some feedback on my approach. I'd be happy to provide code snippets or screenshots if you'd like.

    Thanks <3