Hi,
I’m trying to throw a ball with given spin value and speed but after bouncing the moverotation keeps increasing. Is there a way to decrease it after bouncing? The gravity and mass are active, I use a physic material with a friction at 1 on both objects, the ball and the collider but it doesn’t change a thing. I’d like it to decrease slowly but I couldn’t find a way to do it. Here is the code for the ball :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class objSpin3 : MonoBehaviour
{
public float spinz = 0;
Rigidbody2D Rb3;
bool spacepressed = false;
private void Start()
{
Rb3 = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
if (Input.GetKey(KeyCode.RightArrow))
{
spinz = spinz - 20;
}
if (Input.GetKey(KeyCode.LeftArrow))
{
spinz = spinz + 20;
}
Rb3.MoveRotation(Rb3.rotation + Time.fixedDeltaTime * spinz);
Debug.Log(Rb3.rotation + " & " + Time.fixedDeltaTime * spinz);
if (Input.GetKey(KeyCode.Space))
{
if (spacepressed == false)
{
Rb3.gravityScale = 1; //0 by default
Rb3.AddForce(new Vector2(500, 500));
spacepressed = true;
}
}
}
}
I just don’t understand why it goes on increasing although I don’t press left or right arrow anymore. If I turn spinz to 0 after pressing space, it completely stops the rotation.