using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody2D rb;
public Transform groundCheck;
public LayerMask groundLayer;
This is the bare minimum of information to report:
what you want
what you tried
what you expected to happen
what actually happened, log output, variable values, and especially any errors you see
links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)
The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?
Also, review how to post code: the above code is damaged by mis-posting.
If you post code, only post the relevant code and always use the format button above. Do not post photographs of code.
If you just have a bug, here’s how to reason about it:
Time to start debugging!
By debugging you can find out exactly what your program is doing so you can fix it.
Use the above techniques to get the information you need in order to reason about what the problem is.
You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.
Once you understand what the problem is, you may begin to reason about a solution to the problem.
Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.
Hi
thanks for the advice!
This was my first time using the unity forums, and i should have been more clear about the problem and the code. The problem is that for the movement, the horizontal variable is showing which way the player is moving, -1, 0, 1. it is being multiplied by the target speed variable, which gradually increases until it hits the max speed. the horizontal variable is only changing gradually from 0 to 1 when acceleration is happening. during the deceleration, there is none because it is just set to 0. i hoped this helped, but i am new to unity and coding in general, so i am still trying to figure this out.
I think to make it work i would need to set it to 1 until the speedmultiplier variable is zero, but i am unsure how to go about doing this. the horizontal variable must still be able to be set to -1, so the player is able to go both right and left.
It sounds like you’re just trying to change a quantity (speed) over time, rather than instantaneously, and have it work either slowing down or speeding up. Is that the question?
If so…
Smoothing a change between any two particular values:
You have currentQuantity and desiredQuantity.
only set desiredQuantity
the code always moves currentQuantity towards desiredQuantity
read currentQuantity for the smoothed value
Works for floats, Vectors, Colors, Quaternions, anything continuous or lerp-able.