Help! Bounce Machanic not working how how I want it to
I want to bounce a ball, but when the ball hits the ceiling the drag of the ball decreases or just changes to zero, the the ball waits A few seconds to turn the drag back on to simulate a bounce, but he code I wrote just laeves the drag at 1 when it his the ceiling and lands on the platform. Please Help!
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class PlayerJump : MonoBehaviour {
public AudioClip jumpClip;
public Rigidbody2D rigidBody;
public int movementSpeed, waitTime;
bool hasHitCeiling;
void Update () {
}
public void MoveRight(){
transform.position += Vector3.right * Time.deltaTime * movementSpeed;
}
public void MoveLeft(){
transform.position += Vector3.left * Time.deltaTime * movementSpeed;
}
void OnCollisionEnter2D(Collision2D other){
if(other.gameObject.tag =="Ceiling"){
rigidBody.drag = 1;
hasHitCeiling = true;
if(other.gameObject.tag =="Hands"){
StartCoroutine(ChangeBounce());
}
}
}
IEnumerator ChangeBounce(){
yield return new WaitForSeconds(waitTime);
rigidBody.drag = 0f;
hasHitCeiling = false;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612074323im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Ball passes through the floor on movement 1 Answer
How to predict where the soccer ball should be intercepted by an AI player after being kicked? 0 Answers
BallShooting Game Issue with Detecting ball stopping when rolling uphill 1 Answer
Racquet in VR, doesnt hit the ball, and sometimes it "sticks" to the ball. 1 Answer
Curves on Unity 1 Answer