Question by
KermitDev · Sep 10, 2021 at 01:23 AM ·
unity 5scripting problemprogrammingplayer movement
Velocity in Player Movement Problem?
So I am making a player movement script (2D) and I am adding a velocity to the player, and when I add velocity the player is all "Icy" and slides, so I made the velocity 0,0 if the player has no input, only problem is that if the player falls down they are basically in slow motion (no velocity), any way to fix this?
code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float forceSide;
public float forceUp;
public Rigidbody2D RB;
void FixedUpdate()
{
if (!Input.anyKeyDown)
{
RB.velocity = new Vector2(0,0);
}
if (Input.GetKey("d"))
{
RB.velocity = new Vector2(forceSide, 0);
}
if (Input.GetKey("a"))
{
RB.velocity = new Vector2(-forceSide, 0);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Game Object 2 different movement pivots 0 Answers
Camera Help 0 Answers
Scroll-view Database 0 Answers
Renderer.materials not working in void update() 2 Answers
Unity animator always running only one animation...... 1 Answer