Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Bepu physics integration #2131

Merged
merged 525 commits into from
Nov 23, 2024
Merged

Conversation

Eideren
Copy link
Collaborator

@Eideren Eideren commented Jan 28, 2024

PR Details

Adds support for Bepu Physics as an alternative physics engine, we'll keep the current one but will move our focus towards this new one instead.

Motivation

Unified ecosystem, improved performance, flexibility and debugging experience compared to Bullet's physics engine.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

Post release

A huge thanks goes to @Nicogo1705 and @Doprez for working on this. As well as @RossNordby for Bepu and dealing with our nonsense.

COMMIT HISTORY HAS BEEN PRESERVED, DO NOT SQUASH OR REBASE - JUST MERGE

Doprez and others added 30 commits December 21, 2023 19:27
# Conflicts:
#	Stride.BepuPhysics.Navigation/Processors/RecastMeshProcessor.cs
removed auto adding render feature
Add distance handler to gravityGun with mouse wheel
Add rotation adaptation to camera to gravity gun
Easy performance gain but still crash sometimes
@Eideren
Copy link
Collaborator Author

Eideren commented Oct 6, 2024

@Doprez I removed the demo project from the main solution, it couldn't be built from there anyway. This will take care of the missing packages issue.
As for the character issue it is fixed now.
I also created a test to cover the raycast issue you mentioned earlier but could not repro it in the current state. If you do find it again let me know.

@Doprez
Copy link
Contributor

Doprez commented Oct 6, 2024

@Doprez I removed the demo project from the main solution, it couldn't be built from there anyway. This will take care of the missing packages issue. As for the character issue it is fixed now. I also created a test to cover the raycast issue you mentioned earlier but could not repro it in the current state. If you do find it again let me know.

Sounds good! The issue wasnt actually the raycast, it was the fact that the CharacterComponent kept a reference to a disposed object and then tried to look for that reference in the contact removed handler. Ill mess around with your changes and test it out. It was this line that caused it https://github.com/Eideren/xenko/blob/cc05d516d22e0d49b6c1bdc8d29f40520bb4f9eb/sources/engine/Stride.BepuPhysics/Stride.BepuPhysics/CharacterComponent.cs#L158 since the component that was supposed to be returned was removed when the scene is set to null.

I can also create the situation that caused the problem in a repro later it was pretty easy to recreate once I figured out where it was happening.

@Doprez
Copy link
Contributor

Doprez commented Oct 13, 2024

I just tested the issues I was having with removing objects touching the character component and I cant seem to recreate it anymore!

edit: Also the test you added for OnContact removal should be exactly what was happening to me.

@Doprez
Copy link
Contributor

Doprez commented Oct 23, 2024

One thing to mention about the character controller changes. It only jumps while moving, when standing still it does not seem to jump at all for some reason. I can look into it in a bit but maybe you already know why.

@Eideren
Copy link
Collaborator Author

Eideren commented Oct 24, 2024

@Doprez I can't repro in the characterscene demo, what's your setup ?

@Doprez
Copy link
Contributor

Doprez commented Oct 24, 2024

Maybe its my PlayerMover class then? here is my jump code:

	public override void Update(float deltaTime)
	{
		if (_queueJump.TryReceive()) QueueJump();

		Jump();
        }

	private void QueueJump()
	{
		// Jump is queued to allow for a small time frame to press the jump button.
		// This is to allow for a more responsive jump.
		// I may want to base the timer on when the isGrouded state is true so that the player can jump ledges without needing to be grounded.
		_jumpQueued = true;
		_jumpTimeFrame.Start();
	}

	/// <summary>
	/// makes the player jump.
	/// <para>power is determined by the JumpPower variable and uses the CharacterComponent.IsGrounded variable to validate if player can jump.</para>
	/// </summary>
	public void Jump()
	{
		if (!_isCrouched && _jumpQueued && _jumpTimeFrame.ElapsedMilliseconds < _jumpTimeLeniencyMilliseconds)
		{
			_jumpTimeFrame.Reset();
			_jumpQueued = false;
			_character.JumpForce = JumpPower;
			_character.TryJump();
		}
	}

And it gets the input for jump like this:

			if (Input.IsKeyPressed(key))
			{
				JumpEvent.Broadcast();
			}

Ill try out the demo character later this one was mostly taken from the Bullet demo so maybe I mixed something that was wrong.

* navigation component overhaul

* Removing redundant code

* move to GameSystem

* Updated DotRecast

* fix world transofrm move bug

* added build time property

* More settings!

* fix forward to be Z

* Eiderens a genius fixed move

* docs and extra options for tryfindpath

* omit string value
@Doprez
Copy link
Contributor

Doprez commented Nov 2, 2024

Sorry, I meant to get back sooner for the CharacterController issue I was having. It does seem to be fine when using the demo code so I must have had something weird with my previous implementation.

… no longer necessary.

This reverts commit 3f710c6.
This commit is part of another PR on Stride/master which will be merged at a later date.
@Eideren Eideren force-pushed the bepu_integration branch 2 times, most recently from 36c9807 to 413c24d Compare November 2, 2024 10:44
@Eideren Eideren changed the title [Physics] Bepu integration feat: Bepu physics integration Nov 23, 2024
@Eideren Eideren merged commit 62d7fa2 into stride3d:master Nov 23, 2024
3 checks passed
@Eideren Eideren deleted the bepu_integration branch December 13, 2024 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants