pymunk - Tripping Segment - pymunk

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.

Related

Fastest way to determine line of sight on a grid

I am improving a video game of mine where I currently have the problem that NPCs can shoot through walls. In order to fix this issue, I have decided to completely re-do my work regarding ground combat.
I use a tight grid for finding paths from any point A to B. I store my grid as an image-like structure and use Jump Point Search for the pathfinding itself. My goal is to find a location that is as far away from the enemy as possible (limited by the firearms's range) that also has a direct line of sight to the enemy.
In my latest approach, I determined all nodes in my grid that are within weapon range and that are connected to the enemy's location (colored in green in the image below). The final missing part is filtering these points so that only the points with a valid line of sight remain.
I can also detect the border lines (colored in blue) very fast. I could check for every node, if a line from this node to the enemy would intersect any border line. If that is not the case, I have clear line of sight. However, I assume this to be neither fast nor the optimal solution.
Do you have any ideas or suggestions? I am glad for any hint!
I visualized the grid in the following image to give you an idea of what I am talking about. If a character would stand in the lower right green area, he could not shoot the enemy in the upper left area because of missing line of sight.

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.

Calculate fall time in SpriteKit

I am using SpriteKit and I need to calculate the fall time of an object (since it changes depending on the screen size). The problem is that the gravity of the scene is given in m/s^2, but all distances are measured in points.
I have tried to find the conversion between points and meters, but it was not very successful.
Any suggestions in how to deal with it?
You may be able to use something like this (A distance calculator written by another on StackOverflow) to calculate the distance between your node and the point directly below it near the ground or another empty node, then plug that distance into an equation to calculate the time.
Unfortunately, I can't give you any code because I've never tried this myself.

How to get a ball/sphere to stop

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.

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.