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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

How should i do character control script ??

Discussion in '2D' started by osmancik, Mar 14, 2018.

  1. osmancik

    osmancik

    Joined:
    Mar 13, 2018
    Posts:
    2
    Hi all!
    I am trying to make a desktop game like Dead Cells or Hollow Knight.

    There are a few things that confuse my mind. Firstly how should i do character control ? what should i use ?
    Somebody use transform.position but other use rigidbody2d. unity recommend rigidbody2d. people say if i use transform.position its can be problem (problem in colliders). in your opinion which should i use ??

    hollow knight made unity. what did they use ? if you make a game like that what you will use ?
    i think i will use rigidbody2d but which one ? (velocity-addforce-moveposition or others ?)
    please share your opinion. thanks.
    (sorry for my english)
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    I'm afraid I don't know either of those, but I can maybe at least provide some general advice.

    True.

    False.

    False. (Well, probably true that people say it, but...)

    It depends on your game. Is your character going to be knocking over boxes? Stacks of barrels? Towers of pigs? If it's doing something like that, then you need a rigidbody2d. Otherwise, you don't, and you should make your life easier by just moving the transform directly.

    It is impossible to tell from the outside. However, if we look at other classic 2D games — Mario, Transylvania, Metroid, Sonic, etc. etc. — not one of them had or needed a physics engine. And you get much better control without it.

    See above. It depends entirely on whether I need to push/knock over stuff in the environment.

    I think you probably will too, because most beginners do. Only later do they understand that they have chosen the way of pain.

    That said, if you do need to use physics for your character controller, you'll probably want to use MovePosition with it, so you still have some amount of control over how the character moves.

    Best,
    - Joe
     
  3. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    Just be careful if you mix transform. and rigidbody. Transform.position will be calculated every frame. The physics only at fixed time steps. As example, you have the player which is infront of a wall. With the rigidbody2d.velocity the player cannot go throug the wall. With transform.position you can warp the player into the wall (because the next physic calculating step can be in next 0.2 s). Also use rigidbody2d. if you are working with colliders (or event like OnTriggerEnter2D) and transform. if just the simple moving is needed.
     
    osmancik likes this.
  4. osmancik

    osmancik

    Joined:
    Mar 13, 2018
    Posts:
    2
    i was trying to see the difference between them. that informations are helped me to get a few ideas, thanks all :)


    what is the difference between rigidbody2d.moveposition and rigidbody2d.position ?
     
    Last edited: Mar 14, 2018
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    Rigidbody2D.MovePosition moves the rigidbody in a way that the physics engine can track, so it can calculate collisions along the way for example.

    Assigning to .position directly "warps" to the new position, leaving the physics engine scrambling to catch up, and unable to calculate things like collisions on the way.