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 :
public class objSpin3 : MonoBehaviour
public float spinz = 0;
bool spacepressed = false;
private void Start()
Rb3 = GetComponent<Rigidbody2D>();
spinz = spinz - 20;
spinz = spinz + 20;
Rb3.MoveRotation(Rb3.rotation + Time.fixedDeltaTime * spinz);
Debug.Log(Rb3.rotation + " & " + Time.fixedDeltaTime * spinz);
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.
your move rotation code is executed if you press a key or not. set moverotation when either key is pressed. if none is pressed, don't call it.
Answer by KillVince
Mar 21 at 12:49 PM
The problem is that I want to keep the spin when we press nothing, before throwing the ball with space. If I use the Rb3.MoveRotation when a key is pressed only it stops spinning completely when nothing is pressed.
nobody has an idea?
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
117 People are following this question.
How to Set a Single Axis Rotation of a GameObject?
Parenting an object causes it to change rotation
UI compass pointing to a 3D object
How do i fix this default rotation?
Sprites only rotate by 90 degrees