I m new to game dev, searching for a community to help, I was just creating jelly shift replica as practice, I m stuck on a concept, (if you don't know about , there's a cube which scales up and down on touching), so i scale it using transform.local scale and increment in the x and decrement in the y while pressing up arrow key and vice versa on pressing down arrow, alongside, i m moving the cube through constant velocity by rb.velocity = transform.forward * forwardspeed in fixed update function. scaling is in update function, Problem is that when i move forward the cube using rb.velocity, while scaling, it hovers up the ground, because it scales down on y axis from both ends and hovers, but when i move it using transform.translate, it sticks to the ground, even on scaling, it doesn't hover up, i have the gravity and all the things, but i don't know why this happens, following is the code, I m worried why i cant get these concepts, Please if anyone can help me.
Jelly Shift Game Link: https://play.unity.com/mg/other/webgl-builds-350432
void Update()
{
scaleCube();
}
private void FixedUpdate()
{
movingCube();
}
private void scaleCube() {
float verticalInput = Input.GetAxis("Vertical");
if (verticalInput > 0)
verticalInput = 1;
else if (verticalInput < 0)
verticalInput = -1;
float newScaleX = transform.localScale.x - verticalInput * scaleSpeed * Time.deltaTime;
float newScaleY = transform.localScale.y + verticalInput * scaleSpeed * Time.deltaTime;
// Clamp the scale within the specified range
newScaleX = Mathf.Clamp(newScaleX, minX, maxX);
newScaleY = Mathf.Clamp(newScaleY, minY, maxY);
transform.localScale = new Vector3(newScaleX, newScaleY, transform.localScale.z);
}
private void movingCube()
{
// transform.Translate(Vector3.forward * ForwardSpeed* Time.deltaTime);
cubeRB.velocity = transform.forward * ForwardSpeed;
}
// Update is called once per frame