void CreatePoint2PointConstraint() { cubeRigidBody.LinearFactor = Vector3.Zero; cubeRigidBody.AngularFactor = Vector3.Zero; sphereRigidBody.LinearFactor = new Vector3(1, 1, 1); sphereRigidBody.AngularFactor = new Vector3(1, 1, 1); currentConstraint = BepuSimulation.CreateConstraint(ConstraintTypes.Point2Point, cubeRigidBody, sphereRigidBody, Matrix.Identity, Matrix.Translation(new Vector3(4, 0, 0))); simulation.AddConstraint(currentConstraint); constraintNameBlock.Text = "Point to Point"; //there are no limits so the sphere will orbit once we apply this sphereRigidBody.ApplyImpulse(new Vector3(0, 0, 18)); }
public override void Start() { //simulation = this.GetSimulation(); simulation = SceneSystem.SceneInstance.GetProcessor <BepuPhysicsProcessor>()?.Simulation; simulation.Gravity = new Vector3(0, -9, 0); cubeRigidBody = cube.Get <BepuRigidbodyComponent>(); cubeRigidBody.CanSleep = false; sphereRigidBody = sphere.Get <BepuRigidbodyComponent>(); sphereRigidBody.CanSleep = false; // Create the UI constraintNameBlock = new TextBlock { Font = Font, TextSize = 55, TextColor = Color.White, }; constraintNameBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 0)); constraintNameBlock.SetCanvasRelativePosition(new Vector3(0.5f, 0.83f, 0)); Entity.Get <UIComponent>().Page = new UIPage { RootElement = new Canvas { Children = { constraintNameBlock, CreateButton("Next", Font, 1), CreateButton("Previous",Font, -1) } } }; // Create and initialize constraint PhysicsSampleList.Add(CreatePoint2PointConstraint); //PhysicsSampleList.Add(CreateHingeConstraint); //PhysicsSampleList.Add(CreateGearConstraint); //PhysicsSampleList.Add(CreateSliderConstraint); //PhysicsSampleList.Add(CreateConeTwistConstraint); //PhysicsSampleList.Add(CreateGeneric6DoFConstraint); RemoveConstraint(); PhysicsSampleList[constraintIndex](); //Add a script for the slider constraint, to apply an impulse on collision cubeRigidBody.ProcessCollisions = true; Script.AddTask(async() => { while (Game.IsRunning) { var collision = await cubeRigidBody.NewCollision(); //if (!(currentConstraint is SliderConstraint)) continue; if (collision.ColliderA != sphereRigidBody && collision.ColliderB != sphereRigidBody) { continue; } sphereRigidBody.LinearVelocity = Vector3.Zero; //clear any existing velocity sphereRigidBody.ApplyImpulse(new Vector3(-25, 0, 0)); //fire impulse } }); }