How to get a ball/sphere to stop - unity3d

I got a field in unity3d that has some depressions in it (like small holes). The field's slope always leads towards the nearest depression.
A sphere is dropped at random somewhere in the field, rolls around a bit until it stops in one of the depressions.
The problem is, this is taking too long. It could roll around for 5-10 seconds until it stops. I'd like to stop faster.
Any ideas how I can achieve this?
Edit: The main issue is when the ball is next to the depression, but it has speed that is 90 degrees from the hole, then it starts going in circles and takes a while to stop.

Ok, after getting some advice in the comments, and experimenting, this is the way I solved it:
Apply a small measure of strength towards the depression
If the current velocity is more than 30 degrees away from the center of the depression, slow the ball (apply strength in the opposite direction of the velocity)
IF the ball gets very near the center of the depression, stop it and place it in the center
Thanks for all the tips. If anyone comes up with a better way, I'm still open to suggestions.

Related

Forward facing vector is a bit offset

I am making an FPS game and I need for the forward facing vector to hit exactly where the crosshair is aiming.
This is my current blueprint.
It takes all references from the camera position where the players head should be. (as it usually is in FPS games).
When "shooting" the vector it is slightly offset though. (pink dot near crosshair)
Things I have tried:
Increasing distance of vector makes the problem go away but it then becomes inconsistent, which means it's a bad solution to the problem :(
Manually changing axis values, but that was also very inconsistent.
Changing between 3 different nodes of taking rotation from the camera, they all (didn't) work the same way :/
Maybe there is an issue of the values that I am taking, although the starting position of the camera seems to be correct.
Thank you for any insight you may have!
Suggested by user Ruzihm the issue was that the crosshair was off-center. My blueprints were actually okay.
So for anyone looking see if your crosshair is in the center.

pymunk - Tripping Segment

I am trying to do the following:
Vertical line segment (with mass) moving forward (# fixed velocity) on the ground (no friction), tripping over a point (rock) on the ground. I am looking for the segment point in contact with the ground to stop forward velocity and have the segment tip over that point taking into consideration conservation of momentum of the evenly distributed mass.
I have honestly tried for hours trying to figure this out. The closet I get is a collision but the segment does not tip, the whole thing just instantly stops and the top of the segment slowly start tipping backwards.
Any help would be appreciated.
Try setting the elasticity of the objects to 1.

How to find direction (in radians or degrees) of a physics body

I have a physics body that gets hit and rotates a lot. I want to limit the amount it can rotate (only 45 degrees in each direction or something) and I wanted to try to do that by applying torque if the direction goes past a certain point. I'm ok with the sprite wobbling back and forth (it's a bird).
I'm open to other suggestions on how to limit the rotation as well.
Thanks in advance!
Edit: I've already tried using zRotation (I printed it out and it was always 0.) I also tried using the vector but that gave me the direction the sprite was going.

JavaFX - Creating basic jumping mechanic

I've been looking for awhile now for someone who had created a good example of making good physics in JavaFX, or even just a 'basic jumping mechanic' as the title says. I can't really find any information on it and I'm not really sure how to implement the idea.
All I want is a basic example, or just an explanation, or even just a point in the direction of what element of JFX I'm going to use.
Any help is appreciated.
Thanks
I'm assuming you already have some sort of game loop that ticks 60 times a second such as the AnimationTimer. If you want the jump height to be something like 200 pixels, you need to set and objects y-velocity (velocity is added to the objects location every tick) to a large negative number (as the object is moving upwards) and add a smaller amount every tick to this velocity until it hits zero, (this will be the top of the jump) and then keep adding this value to the y-velocity until it reaches the ground or collides with something. (This value will be your gravity constant)
In essence, you need to set the y-velocity to a high value then take away small increments every tick to slow the jump until the y-velocity hits 0, then begin adding the gravity constant again until the object hits the ground, hope this helps :)

Need Unity character controller to make sharp 90 degree turns and not slide when turning

I'm using the first person controller for my characters movement. On a left arrow keypress, I'd like the character to instantly rotate 90 degrees and keep moving forward. Currently, when I hit the arrow key, the character makes the sharp 90 degree turn, but the forward momentum the character previously had takes a second to wear off so the character ends up sliding in the direction he was previously moving a short bit.
The closest example I can think of to visually explain what I'm trying to do is how the character turns sharp in Temple Run. How my game is currently working, if I had the character on a ledge make a sharp left turn, he'd likely keep the original momentum and slide off the edge right after he turns.
Since my character is running on the x/z axis, I'm wondering if there would just be some way to maybe swap the directional velocity/momentum? The speed the character had on the x axis would instantly be switched to the z when it turns and the other would be set to zero. I'm obviously open to any solution that accomplishes what I'm looking for.
I dug into the CharacterMotor class in the first person controller, but have yet to find what part I can tweak to accomplish this.
I'd greatly appreciate any help.
Thank you.
You can try to stop the velocity of the Rigidbody before turning.
this.rigidbody.velocity = Vector3.zero;
this.rigidbody.angularVelocity = Vector3.zero;
If you want the object to continue like it did, you can try playing around with it by saving the current velocity in a variable, setting it to 0, rotate it and then putting back the old velocity (still forward).
If it works with global vectors (so from the point of view of the world, not the object), then you can try negativing the velocity, actually causing it to go 'backwards'. I can't test it for now but either way I think you need to set the velocity to zero first before turning the character.