friction not working correctly in my 2d game - unity

ken

I am developing a 2d game in unity, and I am trying to add friction to slow the player down when he is on the ground. I launch the player into the air with the rigidbody's add force. I have heard of physics materials, and am currently trying to use them. I am using the 2d version of them, I made one material which had high friction. I add the material to the floor, and then I play the game, and my character is still sliding on the floor. I thought the problem might be with the player not having a physics material, so I added one. It still didn't work.

  • I tried doing different combinations with the different materials.

  • I tried attaching a rigidbody, but kinematic to the floor.

  • I tried looking it up, and couldn't find an answer.

Here is the code that moves the player:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    public bool isGrounded = true;
    public float fireForce;
    Rigidbody2D rb;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        camera = camObj.GetComponent<Camera>();
    }
    void Update()
    {
        RotateToPoint();
        Fire();
    }
    void OnCollisionEnter2D(Collision2D obj)
    {
        if (obj.gameObject.tag == "surface")
        {
            isGrounded = true;
        }
    }
    void OnCollisionExit2D(Collision2D obj)
    {
        if (obj.gameObject.tag == "surface")
        {
            isGrounded = false;
        }
    }
    void Fire()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0) && isGrounded)
        {
            rb.AddForce(transform.up * fireForce, ForceMode2D.Impulse);
        }
    }
}

I do not know if I am approaching the problem correctly. If I am not, does anyone know how to avoid slippery game objects. Any help would be appreciated.

ken

Adding a higher angular drag was the solution to my problem. Angular drag is what slows the object down along its rotation. Friction may not always be the problem. Rigidbody2D component values

Notice the two highlighted variables. You might want to raise these values (I changed angular drag from its default) to something higher. Adding the physics material might help, you should try this if this first solution doesn't work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Unity Networking 2d game, ClientRpc not working correctly

Unity 2D scripted friction equation

Force on horizontal movement on unity 2D character controller is not working correctly

Unity 2d game - why is my static stat resetting to 100 when scene changes?

2d unity game asking permissions which i didn't mentioned in my code

Why does my game load another scene when i click? UNITY 2D

Why do my 2D objects not collide in Unity despite that the layers are set correctly?

Unity build not building game correctly

Unity2D Movement - velocity not working correctly

Android 2D Game Development Using UNITY Game Engine

Trying to program a 2D Unity code that shows if my character is grounded or not and it's not working

Game of Life algorithm not working correctly

I want to create in-house store for my 2D game in unity should I create it by using PlayerPrefs or Serializedfield

Is my GPU working correctly?

3D Classes in a 2D Unity Game

2D game development with Unity3D

Unity: Rotation of an Object is not working correctly

Unity3d not working correctly with Mac OS high Sierra

How to design my online Game Server for Unity3d?

Make Bike stable in Unity 2D game

Create a basic 2D platformer game in Unity

Unity Beginner - 2d game: detect position of tap on quad

Weird collision bug in Unity 2d game

Unity 2d game movement script issue - unable to jump

How to find the length of a 2D game object in Unity

Using Parallaxing for a 2D game in unity Understanding the Z axis

Unity 2d game screen messed up bug

Character Collision problem in unity 2D game

Trying to fix the scale of a game object in Unity 2D