Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Discussion Simulating physics collision and movement, like N++

Discussion in '2D' started by ArkanisGath, Mar 14, 2023.

  1. ArkanisGath

    ArkanisGath

    Joined:
    Mar 4, 2023
    Posts:
    1
    Hi,
    how would one approach this kind of movement?



    Using Unity's physics is completely out of the question, I suppose.
    The main problem would be the slopes. The player should be able to run up slopes, but depending on the slope degree it should be pushed backwards and downwards.

    I was thinking of using a collision system based on a grid, since what I have in mind uses tiles anyway. I would check all the player adjacent tiles and then start from there. If I'm moving right and I'm entering a 45º tile, then I know that's a slope I should be able to climb, but also one that pushes you downwards at a certain force. If it's a curved convex or concave tile, the same, etc.

    The sprite (and the collider, which I think the best fit would be capsule/circle and not box) should rotate together with the slope as well.

    How would you approach something like this? I'm not asking for code (although if you know of any asset, let me know), rather how you would manage the collisions with slopes (the velocity, the jumping, etc. are much easier to do, the puzzle are the slopes themselves).
     
    Last edited: Mar 14, 2023
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,801
    Why? By "Unity Physics" do you mean a Dynamic body? Because you're better describing it as that. "Unity Physics" means using any of the components provided, Rigidbody2D, Colliders, Joints, Effectors and collision detection including physics queries.

    You need to write or use a controller. The "Unity Physics" system provides you with everything you need including a wealth of physics queries.

    A collision with a slope isn't a specific case. A collision is a collision. How you move after a collision is all up to you. For instance, this example of Kinematic motion where you "slide" along surfaces can be seen here:


    In the end, Kinematic motion is just queries to detect your environment then you applying movement.
     
    ArkanisGath and Kurt-Dekker like this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    37,222
    Adding to the great stuff MelvMay posted above, here's a video about making a custom 3D physics character controller to get the feel the guy wanted:

    Yes it is 3D but 100% of what he suggests is applicable in some way to 2D physics.



    That guy has a ton of other great custom physics devlog videos... really good stuff.
     
    ArkanisGath and MelvMay like this.
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,801
    Chubzdoomer and Kurt-Dekker like this.