Im new to the physics. My ball golf ball is moved with AddForce, ive got materials set on the wall for bounciness and the ball itself has most the friction right now.
The issue is the golf ball never really slows down to the point that id want to hit it again.
Right now all im doing is checking if its .velocity on the entire vector is <= 3 then I manually set velocity to 0. This isn’t the best because it still takes forever because each x,y,and z need to be 3 or below. and has some weird intereactions and i find the ball getting stuck in mid air sometimes.
What would be your solution?
Have you tried increasing its weight?
I think the most success is from setting a really high drag when the ball reaches slow enough speed.
Im just having trouble writing enough if conditions that will set the drag back to normal after its actually stopped.
I will comment my code and attempt to bring something here for help
Here is the example, not working. I use mouse1 to shoot the ball with force(turning on the shotBall bool) Whats happening is the ball is randomly stopping momentarily after colliding with walls, but a few of the velocity vectors are still going up/down into the negatives and positives. Why didn’t my ball completely stop when I set its velocity to 0? Not only that but I allow the ball to be hit again if the shotball is false. So the ball is moving and yet im able to shoot it again. bizarre.
if (shotBall)
{
ballMovingTime += Time.deltaTime;
if(ballMovingTime >= 1)
{
CheckToSlowDown();
}
}
above code starts a timer so thee initial movement itnst stoppe but then starts to check if its slow enough with thee code below
void CheckToSlowDown()
{
Vector3 testVector3 = new Vector3(.05f, .05f, .05f);
//
if (cinderlingRB.velocity.x <= testVector3.x && cinderlingRB.velocity.y <= testVector3.y && cinderlingRB.velocity.z <= testVector3.z)
{
cinderlingRB.drag += 0.7f;
Vector3 testVector4 = new Vector3(0, 0, 0);
//
if (cinderlingRB.velocity.x <= testVector4.x && cinderlingRB.velocity.y <= testVector4.y && cinderlingRB.velocity.z <= testVector4.z)
{
ballMovingTime = 0;
cinderlingRB.velocity = testVector4;
shotBall = false;
}
}
}
this might prove useful, he messed around with the slowing down part around the middle of the video.
https://www.youtube.com/watch?v=fvlakpubZQk
also, your if statements are weird and not needed…
‘testVector4’ will always be (0,0,0) yet you are checking against its values, in a way that only catches positive positions (IE negative X/Y/Z is discarded as zero)
why not just test for velocity.magnitude/sqrMagnitude?
what’s wrong with just apply drag and letting it come to a stop?
@WarmedxMints_1 increasing the weight shouldn’t make it stop any sooner or later (given the same speed), it would make the force applied to it to have less effect (unless using a variation of the force mode that doesn’t take mass into account), what the OP wants to do is probably just add drag and angular drag to the ball, and I mean just have a value for this, i don’t see the need to modify it on the fly.
1 Like
When you say my If statement is only checking positive values, yes, I noticed this. I just don’t know how else I could write the if statement to correctly check for positive and negative values. Ultimately I think this is why the whole thing is scrwing up because it stops pretty well…it just slowly rolls into the negative velocities and my code doesn’t know that…
I honestly have no clue what velocity.magnitude/sqrMagnitude is used for. Can you explain this better?
Thanks for the video, ill watch it.
Just writing to say that ive switched to checking velocity.magnitude to obtain how fast its going in th postitive and I check against this.
Ive moved the call to CheckToSlowDown into fixed update.
it seems to help on everything unless the ball is going up a ramp… the ball will slow down and stay at like 50+ drag so it doesn’t slide down the surface… i guess a solution is to check the angle the ground is before setting the drag…seems complicated
Okay, so ive decided to try and determine the angle below the ball… when I run this, im seeing correct angles (such as 90 while on a flat surface) through the debug.log… yet my bool isn’t setting to false when its on a flat surface. ugh…
public void OnCollisionStay(Collision collision)
{
var orthogonalVector = collision.contacts[0].point - transform.position;
var collisionAngle = Vector3.Angle(orthogonalVector, cinderlingRB.velocity);
Debug.Log(collisionAngle);
if(collisionAngle >= 100 || collisionAngle <= 80)
{
//cinderlingRB.drag = .5f;
onAngle = true;
} else
{
onAngle = false;
}
}