Skip to main content
deleted 3 characters in body
Source Link

Attach Collider2D, RigidBody2D, CharacterController2D to player and use Move Method in FixUpdate. Meanwhile, properties of RigidBody2D: Body Type = Dynamic, Simulated = true, Gravity Scale = 0, Constraints - Freeze Rotation Z = true

using UnityEngine;

[RequireComponent(typeof(Rigidbody2D))]
public class CharacterController2D : MonoBehaviour
{
    #region Move Var

    [SerializeField, Tooltip("Max speed, in units per second, that the character moves.")]
    float speed = 2;

    [SerializeField, Tooltip("Acceleration while grounded.")]
    float walkAcceleration = 20f;

    [SerializeField, Tooltip("Deacceleration while stopped.")]
    float deceleration = 80f;

    [SerializeField, Tooltip("Stop when move input smaller than stopThreshold")]
    float stopThreshold = 0.1f;

    private Rigidbody2D rg;

    private Vector2 velocity;

    public bool isMoving
    {
        get { return velocity != Vector2.zero; }
    }

    #endregion

    private void Awake()
    {
        rg = GetComponent<Rigidbody2D>();
    }

    public void Move(Vector2 moveInput)
    {
        // Move Logic

        if (moveInput.magnitude >= stopThreshold)
            velocity = Vector2.MoveTowards(velocity, speed * moveInput, walkAcceleration * Time.fixedDeltaTime);
        else
            velocity = Vector2.MoveTowards(velocity, Vector2.zero, deceleration * Time.fixedDeltaTime);

        if (velocity.magnitude <= stopThreshold)
            velocity = Vector2.zero;

        Vector2 curPos = new Vector2(transform.position.x, transform.position.y);
        Vector2 nextPos = curPos + velocity * Time.fixedDeltaTime;

        rg.MovePosition(nextPos);
}
```

Attach Collider2D, RigidBody2D, CharacterController2D to player and use Move Method in FixUpdate. Meanwhile, properties of RigidBody2D: Body Type = Dynamic, Simulated = true, Gravity Scale = 0, Constraints - Freeze Rotation Z = true

using UnityEngine;

[RequireComponent(typeof(Rigidbody2D))]
public class CharacterController2D : MonoBehaviour
{
    #region Move Var

    [SerializeField, Tooltip("Max speed, in units per second, that the character moves.")]
    float speed = 2;

    [SerializeField, Tooltip("Acceleration while grounded.")]
    float walkAcceleration = 20f;

    [SerializeField, Tooltip("Deacceleration while stopped.")]
    float deceleration = 80f;

    [SerializeField, Tooltip("Stop when move input smaller than stopThreshold")]
    float stopThreshold = 0.1f;

    private Rigidbody2D rg;

    private Vector2 velocity;

    public bool isMoving
    {
        get { return velocity != Vector2.zero; }
    }

    #endregion

    private void Awake()
    {
        rg = GetComponent<Rigidbody2D>();
    }

    public void Move(Vector2 moveInput)
    {
        // Move Logic

        if (moveInput.magnitude >= stopThreshold)
            velocity = Vector2.MoveTowards(velocity, speed * moveInput, walkAcceleration * Time.fixedDeltaTime);
        else
            velocity = Vector2.MoveTowards(velocity, Vector2.zero, deceleration * Time.fixedDeltaTime);

        if (velocity.magnitude <= stopThreshold)
            velocity = Vector2.zero;

        Vector2 curPos = new Vector2(transform.position.x, transform.position.y);
        Vector2 nextPos = curPos + velocity * Time.fixedDeltaTime;

        rg.MovePosition(nextPos);
}
```

Attach Collider2D, RigidBody2D, CharacterController2D to player and use Move Method in FixUpdate. Meanwhile, properties of RigidBody2D: Body Type = Dynamic, Simulated = true, Gravity Scale = 0, Constraints - Freeze Rotation Z = true

using UnityEngine;

[RequireComponent(typeof(Rigidbody2D))]
public class CharacterController2D : MonoBehaviour
{
    #region Move Var

    [SerializeField, Tooltip("Max speed, in units per second, that the character moves.")]
    float speed = 2;

    [SerializeField, Tooltip("Acceleration while grounded.")]
    float walkAcceleration = 20f;

    [SerializeField, Tooltip("Deacceleration while stopped.")]
    float deceleration = 80f;

    [SerializeField, Tooltip("Stop when move input smaller than stopThreshold")]
    float stopThreshold = 0.1f;

    private Rigidbody2D rg;

    private Vector2 velocity;

    public bool isMoving
    {
        get { return velocity != Vector2.zero; }
    }

    #endregion

    private void Awake()
    {
        rg = GetComponent<Rigidbody2D>();
    }

    public void Move(Vector2 moveInput)
    {
        // Move Logic

        if (moveInput.magnitude >= stopThreshold)
            velocity = Vector2.MoveTowards(velocity, speed * moveInput, walkAcceleration * Time.fixedDeltaTime);
        else
            velocity = Vector2.MoveTowards(velocity, Vector2.zero, deceleration * Time.fixedDeltaTime);

        if (velocity.magnitude <= stopThreshold)
            velocity = Vector2.zero;

        Vector2 curPos = new Vector2(transform.position.x, transform.position.y);
        Vector2 nextPos = curPos + velocity * Time.fixedDeltaTime;

        rg.MovePosition(nextPos);
}
added 66 characters in body
Source Link

Attach Collider2D, RigidBody2D, CharacterController2D to player and use Move Method in FixUpdate. Meanwhile, properties of RigidBody2D: Body Type = Dynamic, Simulated = true, Gravity Scale = 0, Constraints - Freeze Rotation Z = true

using UnityEngine;

[RequireComponent(typeof(CircleCollider2DRigidbody2D))]
public class CharacterController2D : MonoBehaviour
{
    #region Move Var

    [SerializeField, Tooltip("Max speed, in units per second, that the character moves.")]
    float speed = 9;2;

    [SerializeField, Tooltip("Acceleration while grounded.")]
    float walkAcceleration = 75f;20f;

    [SerializeField, Tooltip("Deacceleration while stopped.")]
    float deceleration = 70f;80f;

    [SerializeField, Tooltip("Stop when move input smaller than stopThreshold")]
    float stopThreshold = 0.01f;1f;

    private Rigidbody2D rg;

    private Vector2 velocity;

    public bool isMoving
    {
        get { return velocity.magnitude >=!= stopThreshold;Vector2.zero; }
    }

    #endregion

    private void Awake()
    {
        rg = GetComponent<Rigidbody2D>();
    }

    public void Move(Vector2 moveInput)
    {
        // Move Logic

        if (moveInput.magnitude >= stopThreshold)
            velocity = Vector2.MoveTowards(velocity, speed * moveInput, walkAcceleration * Time.fixedDeltaTime);
        else
            velocity = Vector2.MoveTowards(velocity, Vector2.zero, deceleration * Time.fixedDeltaTime);

        if (velocity.magnitude <= stopThreshold)
            velocity = Vector2.zero;

        Vector2 curPos = new Vector2(transform.position.x, transform.position.y);
        Vector2 nextPos = curPos + velocity * Time.fixedDeltaTime;

        rg.MovePosition(nextPos);
    }
}
```

Attach Collider2D, RigidBody2D, CharacterController2D to player and use Move Method in FixUpdate. Meanwhile, properties of RigidBody2D: Body Type = Dynamic, Simulated = true, Gravity Scale = 0, Constraints - Freeze Rotation Z = true

using UnityEngine;

[RequireComponent(typeof(CircleCollider2D))]
public class CharacterController2D : MonoBehaviour
{
    #region Move Var

    [SerializeField, Tooltip("Max speed, in units per second, that the character moves.")]
    float speed = 9;

    [SerializeField, Tooltip("Acceleration while grounded.")]
    float walkAcceleration = 75f;

    [SerializeField, Tooltip("Deacceleration while stopped.")]
    float deceleration = 70f;

    [SerializeField, Tooltip("Stop when move input smaller than stopThreshold")]
    float stopThreshold = 0.01f;

    private Rigidbody2D rg;

    private Vector2 velocity;

    public bool isMoving
    {
        get { return velocity.magnitude >= stopThreshold; }
    }

    #endregion

    private void Awake()
    {
        rg = GetComponent<Rigidbody2D>();
    }

    public void Move(Vector2 moveInput)
    {
        // Move Logic

        if (moveInput.magnitude >= stopThreshold)
            velocity = Vector2.MoveTowards(velocity, speed * moveInput, walkAcceleration * Time.fixedDeltaTime);
        else
            velocity = Vector2.MoveTowards(velocity, Vector2.zero, deceleration * Time.fixedDeltaTime);

        Vector2 curPos = new Vector2(transform.position.x, transform.position.y);
        Vector2 nextPos = curPos + velocity * Time.fixedDeltaTime;

        rg.MovePosition(nextPos);
    }
}
```

Attach Collider2D, RigidBody2D, CharacterController2D to player and use Move Method in FixUpdate. Meanwhile, properties of RigidBody2D: Body Type = Dynamic, Simulated = true, Gravity Scale = 0, Constraints - Freeze Rotation Z = true

using UnityEngine;

[RequireComponent(typeof(Rigidbody2D))]
public class CharacterController2D : MonoBehaviour
{
    #region Move Var

    [SerializeField, Tooltip("Max speed, in units per second, that the character moves.")]
    float speed = 2;

    [SerializeField, Tooltip("Acceleration while grounded.")]
    float walkAcceleration = 20f;

    [SerializeField, Tooltip("Deacceleration while stopped.")]
    float deceleration = 80f;

    [SerializeField, Tooltip("Stop when move input smaller than stopThreshold")]
    float stopThreshold = 0.1f;

    private Rigidbody2D rg;

    private Vector2 velocity;

    public bool isMoving
    {
        get { return velocity != Vector2.zero; }
    }

    #endregion

    private void Awake()
    {
        rg = GetComponent<Rigidbody2D>();
    }

    public void Move(Vector2 moveInput)
    {
        // Move Logic

        if (moveInput.magnitude >= stopThreshold)
            velocity = Vector2.MoveTowards(velocity, speed * moveInput, walkAcceleration * Time.fixedDeltaTime);
        else
            velocity = Vector2.MoveTowards(velocity, Vector2.zero, deceleration * Time.fixedDeltaTime);

        if (velocity.magnitude <= stopThreshold)
            velocity = Vector2.zero;

        Vector2 curPos = new Vector2(transform.position.x, transform.position.y);
        Vector2 nextPos = curPos + velocity * Time.fixedDeltaTime;

        rg.MovePosition(nextPos);
}
```
added 1 character in body
Source Link

Attach Collider2D, RigidBody2D, CharacterController2D to player and use Move Method in FixUpdate. Meanwhile, RigidBody2Dis properties of RigidBody2D: Body Type = Dynamic, Simulated = true, Gravity Scale = 0, Constraints - Freeze Rotation Z = true

using UnityEngine;

[RequireComponent(typeof(CircleCollider2D))]
public class CharacterController2D : MonoBehaviour
{
    #region Move Var

    [SerializeField, Tooltip("Max speed, in units per second, that the character moves.")]
    float speed = 9;

    [SerializeField, Tooltip("Acceleration while grounded.")]
    float walkAcceleration = 75f;

    [SerializeField, Tooltip("Deacceleration while stopped.")]
    float deceleration = 70f;

    [SerializeField, Tooltip("Stop when move input smaller than stopThreshold")]
    float stopThreshold = 0.01f;

    private Rigidbody2D rg;

    private Vector2 velocity;

    public bool isMoving
    {
        get { return velocity.magnitude >= stopThreshold; }
    }

    #endregion

    private void Awake()
    {
        rg = GetComponent<Rigidbody2D>();
    }

    public void Move(Vector2 moveInput)
    {
        // Move Logic

        if (moveInput.magnitude >= stopThreshold)
            velocity = Vector2.MoveTowards(velocity, speed * moveInput, walkAcceleration * Time.fixedDeltaTime);
        else
            velocity = Vector2.MoveTowards(velocity, Vector2.zero, deceleration * Time.fixedDeltaTime);

        Vector2 curPos = new Vector2(transform.position.x, transform.position.y);
        Vector2 nextPos = curPos + velocity * Time.fixedDeltaTime;

        rg.MovePosition(nextPos);
    }
}
```

Attach Collider2D, RigidBody2D, CharacterController2D to player and use Move Method in FixUpdate. Meanwhile, RigidBody2Dis properties: Body Type = Dynamic, Simulated = true, Gravity Scale = 0, Constraints - Freeze Rotation Z = true

using UnityEngine;

[RequireComponent(typeof(CircleCollider2D))]
public class CharacterController2D : MonoBehaviour
{
    #region Move Var

    [SerializeField, Tooltip("Max speed, in units per second, that the character moves.")]
    float speed = 9;

    [SerializeField, Tooltip("Acceleration while grounded.")]
    float walkAcceleration = 75f;

    [SerializeField, Tooltip("Deacceleration while stopped.")]
    float deceleration = 70f;

    [SerializeField, Tooltip("Stop when move input smaller than stopThreshold")]
    float stopThreshold = 0.01f;

    private Rigidbody2D rg;

    private Vector2 velocity;

    public bool isMoving
    {
        get { return velocity.magnitude >= stopThreshold; }
    }

    #endregion

    private void Awake()
    {
        rg = GetComponent<Rigidbody2D>();
    }

    public void Move(Vector2 moveInput)
    {
        // Move Logic

        if (moveInput.magnitude >= stopThreshold)
            velocity = Vector2.MoveTowards(velocity, speed * moveInput, walkAcceleration * Time.fixedDeltaTime);
        else
            velocity = Vector2.MoveTowards(velocity, Vector2.zero, deceleration * Time.fixedDeltaTime);

        Vector2 curPos = new Vector2(transform.position.x, transform.position.y);
        Vector2 nextPos = curPos + velocity * Time.fixedDeltaTime;

        rg.MovePosition(nextPos);
    }
}
```

Attach Collider2D, RigidBody2D, CharacterController2D to player and use Move Method in FixUpdate. Meanwhile, properties of RigidBody2D: Body Type = Dynamic, Simulated = true, Gravity Scale = 0, Constraints - Freeze Rotation Z = true

using UnityEngine;

[RequireComponent(typeof(CircleCollider2D))]
public class CharacterController2D : MonoBehaviour
{
    #region Move Var

    [SerializeField, Tooltip("Max speed, in units per second, that the character moves.")]
    float speed = 9;

    [SerializeField, Tooltip("Acceleration while grounded.")]
    float walkAcceleration = 75f;

    [SerializeField, Tooltip("Deacceleration while stopped.")]
    float deceleration = 70f;

    [SerializeField, Tooltip("Stop when move input smaller than stopThreshold")]
    float stopThreshold = 0.01f;

    private Rigidbody2D rg;

    private Vector2 velocity;

    public bool isMoving
    {
        get { return velocity.magnitude >= stopThreshold; }
    }

    #endregion

    private void Awake()
    {
        rg = GetComponent<Rigidbody2D>();
    }

    public void Move(Vector2 moveInput)
    {
        // Move Logic

        if (moveInput.magnitude >= stopThreshold)
            velocity = Vector2.MoveTowards(velocity, speed * moveInput, walkAcceleration * Time.fixedDeltaTime);
        else
            velocity = Vector2.MoveTowards(velocity, Vector2.zero, deceleration * Time.fixedDeltaTime);

        Vector2 curPos = new Vector2(transform.position.x, transform.position.y);
        Vector2 nextPos = curPos + velocity * Time.fixedDeltaTime;

        rg.MovePosition(nextPos);
    }
}
```
added 134 characters in body
Source Link
Loading
deleted 695 characters in body
Source Link
Loading
Source Link
Loading