Hey there! So I want my character to slide on an ice platform, I’ve already tried making a Physics Material 2D and setting the friction and bounciness both to 0, but it doesn’t work. Maybe the solution is to make the slide by code, but I don’t know how to. Here you have the player’s scripts:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public JumpGizmos jg;
private Rigidbody2D rb;
public float speed = 10f;
public int jumpForce = 10;
public float fallMultiplier = 2.5f;
public float LowJumpMultiplier = 2f;
void Start()
{
rb = GetComponent<Rigidbody2D>();
jg = FindObjectOfType <JumpGizmos>().GetComponent<JumpGizmos>();
}
void Update()
{
//======================================= WALK ======================================//
float x = Input.GetAxis("Horizontal");
float y = Input.GetAxis("Vertical");
Vector2 dir = new Vector2(x, y);
Walk(dir);
//======================================= JUMP ======================================//
if (Input.GetButtonDown("Jump") && jg.onGround == true)
{
Jump();
}
if (rb.velocity.y < 0)
{
rb.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
}
else if (rb.velocity.y > 0 && !Input.GetButton("Jump"))
{
rb.velocity += Vector2.up * Physics2D.gravity.y * (LowJumpMultiplier - 1) * Time.deltaTime;
}
}
//======================================= WALK ======================================//
private void Walk(Vector2 dir)
{
rb.velocity = (new Vector2(dir.x * speed, rb.velocity.y));
}
//======================================= JUMP ======================================//
private void Jump()
{
rb.velocity = new Vector2(rb.velocity.x, 0);
rb.velocity += Vector2.up * jumpForce;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JumpGizmos : MonoBehaviour
{
public float collisionRadius = 0.25f;
public Vector2 bottomOffset;
private Color debugCollisionColor = Color.red;
public bool onGround;
public LayerMask groundLayer;
void Update()
{
onGround = Physics2D.OverlapCircle((Vector2)transform.position + bottomOffset, collisionRadius, groundLayer);
}
void OnDrawGizmos()
{
Gizmos.color = Color.red;
var positions = new Vector2[] { bottomOffset };
Gizmos.DrawWireSphere((Vector2)transform.position + bottomOffset, collisionRadius);
}
}