// Update is called once per frame void Update() { // cari gameobject character if (character == null) { character = GameObject.FindGameObjectWithTag("Player").GetComponent <CharacterControllers>(); } // Jika ada waktu tunggu, kurangi if (waitTime > 0) { waitTime -= Time.deltaTime; } if (waitTime < 0) { waitTime = 0; } // Jika harus bergerak dan tidak ada waktu tunggu, panggil aksi didalam pool if (_moveNow && waitTime == 0) { GetPooledAction(); // Debug.Log("i do"); } }
public unsafe override void Initialize(ContentArchive content, Camera camera) { camera.Position = new Vector3(20, 10, 20); camera.Yaw = MathHelper.Pi * -1f / 4; camera.Pitch = MathHelper.Pi * 0.05f; var masks = new CollidableProperty <ulong>(); characters = new CharacterControllers(BufferPool); Simulation = Simulation.Create(BufferPool, new CharacterNarrowphaseCallbacks(characters), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)), new PositionFirstTimestepper()); var random = new Random(5); for (int i = 0; i < 8192; ++i) { ref var character = ref characters.AllocateCharacter( Simulation.Bodies.Add( BodyDescription.CreateDynamic( new Vector3(250 * (float)random.NextDouble() - 125, 2, 250 * (float)random.NextDouble() - 125), new BodyInertia { InverseMass = 1 }, new CollidableDescription(Simulation.Shapes.Add(new Capsule(0.5f, 1f)), 0.1f), new BodyActivityDescription(-1)))); character.CosMaximumSlope = .707f; character.LocalUp = Vector3.UnitY; character.MaximumHorizontalForce = 10; character.MaximumVerticalForce = 10; character.MinimumSupportContinuationDepth = -0.1f; character.MinimumSupportDepth = -0.01f; character.TargetVelocity = new Vector2(4, 0); character.ViewDirection = new Vector3(0, 0, -1); character.JumpVelocity = 4; }
public CharacterInput(CharacterControllers characters, Vector3 initialPosition, Capsule shape, float speculativeMargin, float mass, float maximumHorizontalForce, float maximumVerticalGlueForce, float jumpVelocity, float speed, float maximumSlope = MathF.PI * 0.25f) { this.characters = characters; var shapeIndex = characters.Simulation.Shapes.Add(shape); bodyHandle = characters.Simulation.Bodies.Add(BodyDescription.CreateDynamic(initialPosition, new BodyInertia { InverseMass = 1f / mass }, new CollidableDescription(shapeIndex, speculativeMargin), new BodyActivityDescription(shape.Radius * 0.02f))); ref var character = ref characters.AllocateCharacter(bodyHandle, out var characterIndex);
internal CharacterInput(CharacterControllers characters, int bodyHandle, Simulation simulation, System.Numerics.Vector3 initialPosition, Capsule shape, float speculativeMargin, float mass, float maximumHorizontalForce, float maximumVerticalGlueForce, float jumpVelocity, float speed, float maximumSlope = MathF.PI * 0.25f) { this.bodyHandle = bodyHandle; this.simulation = simulation; #if DEBUG //Console.WriteLine($"======================================= {this.bodyHandle}"); #endif this.characters = characters; ref var character = ref characters.AllocateCharacter(bodyHandle);
void CreateCharacter(CharacterControllers characterCTs, Vector3 position, int unitId) { var shape = new Capsule(0.5f, 1); var shapeIndex = Simulation.Shapes.Add(shape); bodyHandle = Simulation.Bodies.Add(BodyDescription.CreateDynamic(position, new BodyInertia { InverseMass = 1f / 1f }, new CollidableDescription(shapeIndex, 0.1f), new BodyActivityDescription(shape.Radius * 0.02f))); character = new Character(unitId, "test", this, position); character.SetCharacterInput(characterCTs, bodyHandle, Simulation); characters.Add(character.UnitId, character); //Console.WriteLine($"characters[0]: {characters}"); //character = new CharacterInput(characters, position, new Capsule(0.5f, 1), 0.1f, 1, 20, 100, 6, 4, MathF.PI * 0.4f); }
public PhysicsSystem() { //The buffer pool is a source of raw memory blobs for the engine to use. Pool = new BufferPool(); Characters = new CharacterControllers(Pool); //Note that you can also control the order of internal stage execution using a different ITimestepper implementation. //For the purposes of this demo, we just use the default by passing in nothing (which happens to be PositionFirstTimestepper at the time of writing). Simulation = Simulation.Create(Pool, new CharacterNarrowphaseCallbacks(Characters), new PoseIntegratorCallbacks(this, new Vector3(0, -10, 0))); _threadDispatcher = new SimpleThreadDispatcher(Environment.ProcessorCount); _staticContexts = new Dictionary <StaticHandle, object>(); _dynamicContexts = new Dictionary <BodyHandle, object>(); _shapeContexts = new Dictionary <TypedIndex, object>(); }
internal void Initialize(ContentArchive content, Camera camera) { ThreadDispatcher = new SimpleThreadDispatcher(Environment.ProcessorCount); BufferPool = new BufferPool(); camera.Position = new Vector3(20, 10, 20); camera.Yaw = MathF.PI; camera.Pitch = 0; characterCTs = new CharacterControllers(BufferPool); var collider = new BodyProperty <Collider>(); Simulation = Simulation.Create(BufferPool, new CharacterNarrowphaseCallbacks(characterCTs), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0))); //Simulation = Simulation.Create(BufferPool, new MolCallbacks { Collider = collider, Characters= characterCTs }, new DemoPoseIntegratorCallbacks(new System.Numerics.Vector3(0, -10, 0))); CreateCharacter(characterCTs, new Vector3(0, 2, -4), 1); CreateCharacter(characterCTs, new Vector3(0, 3, -2), 2); Simulation.Statics.Add(new StaticDescription(new Vector3(0, 0, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(200, 1, 200)), 0.1f))); }
public unsafe override void Initialize(ContentArchive content, Camera camera) { camera.Position = new Vector3(-30, 40, -30); camera.Yaw = MathHelper.Pi * 3f / 4; camera.Pitch = MathHelper.Pi * 0.2f; characters = new CharacterControllers(BufferPool); Simulation = Simulation.Create(BufferPool, new CharacterNarrowphaseCallbacks(characters), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0))); var ringBoxShape = new Box(0.5f, 1.5f, 3); ringBoxShape.ComputeInertia(1, out var ringBoxInertia); var boxDescription = BodyDescription.CreateDynamic(new Vector3(), ringBoxInertia, new CollidableDescription(Simulation.Shapes.Add(ringBoxShape), 0.1f), new BodyActivityDescription(0.01f)); var layerPosition = new Vector3(); const int layerCount = 10; var innerRadius = 5f; var heightPerPlatform = 2; var platformsPerLayer = 1; var ringSpacing = 0.5f; for (int layerIndex = 0; layerIndex < layerCount; ++layerIndex) { var ringCount = layerCount - layerIndex; for (int ringIndex = 0; ringIndex < ringCount; ++ringIndex) { CreateRing(layerPosition, ringBoxShape, boxDescription, innerRadius + ringIndex * (ringBoxShape.Length + ringSpacing) + layerIndex * (ringBoxShape.Length - ringBoxShape.Width), heightPerPlatform, platformsPerLayer); } layerPosition.Y += platformsPerLayer * (ringBoxShape.Height * heightPerPlatform + ringBoxShape.Width); } Console.WriteLine($"box count: {Simulation.Bodies.ActiveSet.Count}"); Simulation.Statics.Add(new StaticDescription(new Vector3(0, -0.5f, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(500, 1, 500)), 0.1f))); var bulletShape = new Sphere(0.5f); bulletShape.ComputeInertia(.1f, out var bulletInertia); bulletDescription = BodyDescription.CreateDynamic(new Vector3(), bulletInertia, new CollidableDescription(Simulation.Shapes.Add(bulletShape), 10), new BodyActivityDescription(0.01f)); var shootiePatootieShape = new Sphere(3f); shootiePatootieShape.ComputeInertia(1000, out var shootiePatootieInertia); shootiePatootieDescription = BodyDescription.CreateDynamic(new Vector3(), shootiePatootieInertia, new CollidableDescription(Simulation.Shapes.Add(shootiePatootieShape), 10), new BodyActivityDescription(0.01f)); }
public void InitializeWorld() { mGameObjects = new List <NetGameObject>(); //mWorldMap = new WorldMap(); #if _USE_BEPU_PHYSICS space = new BEPUphysics.Space(); space.ForceUpdater.Gravity = new BEPUutilities.Vector3(0, -9.81f, 0); #elif _USE_BULLET_SHARP Broadphase = new BulletSharp.AxisSweep3(new BulletSharp.Math.Vector3(-1000, -1000, -1000), new BulletSharp.Math.Vector3(1000, 1000, 1000)); var conf = new BulletSharp.DefaultCollisionConfiguration(); var dispatcher = new BulletSharp.CollisionDispatcher(conf); world = new BulletSharp.MultiBodyDynamicsWorld(dispatcher, Broadphase, new BulletSharp.MultiBodyConstraintSolver(), conf); world.Gravity = new BulletSharp.Math.Vector3(0, -9.81f, 0); var box = new BulletSharp.BoxShape(50f, 1f, 50f); //box.Margin = 0f; floor = new BulletSharp.RigidBody(new BulletSharp.RigidBodyConstructionInfo(0f, new BulletSharp.DefaultMotionState(), box, new BulletSharp.Math.Vector3(0, -2f, 0))); floor.CollisionFlags = BulletSharp.CollisionFlags.KinematicObject; BulletSharp.Math.Matrix worldTrans = new BulletSharp.Math.Matrix(); worldTrans.M41 = 0f; worldTrans.M42 = -2f; worldTrans.M43 = 0; floor.WorldTransform = worldTrans; //floor.Friction = 0.5f; world.AddRigidBody(floor, BulletSharp.CollisionFilterGroups.DefaultFilter, //BulletSharp.CollisionFilterGroups.Everything); (BulletSharp.CollisionFilterGroups.DefaultFilter | BulletSharp.CollisionFilterGroups.StaticFilter | BulletSharp.CollisionFilterGroups.KinematicFilter | BulletSharp.CollisionFilterGroups.DebrisFilter | BulletSharp.CollisionFilterGroups.SensorTrigger | BulletSharp.CollisionFilterGroups.CharacterFilter ) ); #elif _USE_BEPU_PHYSICS_V2 characters = new BepuPhysics.CharacterControllers(BufferPool); Simulation = Simulation.Create(BufferPool, new BepuPhysics.CharacterNarrowphaseCallbacks(characters), new DemoPoseIntegratorCallbacks(new System.Numerics.Vector3(0, -10, 0))); Simulation.Statics.Add(new StaticDescription(new System.Numerics.Vector3(0, 0, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(50, 1, 50)), 0.1f))); #endif }
public unsafe override void Initialize(ContentArchive content, Camera camera) { camera.Position = new Vector3(20, 10, 20); camera.Yaw = MathF.PI; camera.Pitch = 0; bufferPool = new BufferPool(); var collider = new BodyProperty <Collider>(); //characters = new CharacterControllers(BufferPool); characs = new CharacterControllers(BufferPool); //Simulation = Simulation.Create(BufferPool, new CharacterNarrowphaseCallbacks(characters), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0))); Simulation = Simulation.Create(BufferPool, new MolCallbacks(characs, collider), new DemoPoseIntegratorCallbacks(new System.Numerics.Vector3(0, -10, 0))); character = new PlayerCharacter(1, 1, "noname", 1, this, new Vector3(0f, 3f, 0f)); AddPlayerCharacter(character); //Prevent the character from falling into the void. //Simulation.Statics.Add(new StaticDescription(new Vector3(0, 0, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(200, 1, 200)), 0.1f))); Simulation.Statics.Add(new StaticDescription(new System.Numerics.Vector3(0, -2f, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(200, 1, 200)), 0.4f))); }
public override void Initialize(ContentArchive content, Camera camera) { camera.Position = new Vector3(130, 50, 130); camera.Yaw = -MathF.PI * 0.25f; camera.Pitch = 0.4f; characterControllers = new CharacterControllers(BufferPool); Simulation = Simulation.Create(BufferPool, new CharacterNarrowphaseCallbacks(characterControllers), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0))); DemoMeshHelper.LoadModel(content, BufferPool, @"Content\newt.obj", new Vector3(-10, 10, -10), out var newtMesh); var newtShape = Simulation.Shapes.Add(newtMesh); newts = new QuickList <SponsorNewt>(sponsors2.Count, BufferPool); newtArenaMin = new Vector2(-100); newtArenaMax = new Vector2(100); random = new Random(6); for (int i = 0; i < sponsors2.Count; ++i) { ref var newt = ref newts.AllocateUnsafely(); newt = new SponsorNewt(Simulation, newtShape, 0, newtArenaMin, newtArenaMax, random, i); }
public override void Initialize(ContentArchive content, Camera camera) { camera.Position = new Vector3(130, 50, 130); camera.Yaw = -MathF.PI * 0.25f; camera.Pitch = 0.4f; characterControllers = new CharacterControllers(BufferPool); //Using a PositionLastTimestepper since we control the newts by velocity. Not as critical since they're kinematic and the position targets won't seek to cause undesired penetrations anyway, //but it'll avoid integrating velocities into positions before the solver has a chance to intervene. Simulation = Simulation.Create(BufferPool, new CharacterNarrowphaseCallbacks(characterControllers), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)), new PositionLastTimestepper()); DemoMeshHelper.LoadModel(content, BufferPool, @"Content\newt.obj", new Vector3(-10, 10, -10), out var newtMesh); var newtShape = Simulation.Shapes.Add(newtMesh); newts = new QuickList <SponsorNewt>(sponsors2.Count, BufferPool); newtArenaMin = new Vector2(-100); newtArenaMax = new Vector2(100); random = new Random(6); for (int i = 0; i < sponsors2.Count; ++i) { ref var newt = ref newts.AllocateUnsafely(); newt = new SponsorNewt(Simulation, newtShape, 0, newtArenaMin, newtArenaMax, random, i); }
public CharacterNarrowphaseCallbacks(CharacterControllers characters) { Characters = characters; }
public MolCallbacks(CharacterControllers characters, BodyProperty <Collider> Collider) { this.Characters = characters; this.Collider = Collider; }
// Use this for initialization void Start() { characterControllers = new CharacterControllers(this.gameObject, Speed, Gravity, JumpPower, JumpTimeMax, JumpDownTime, JumpTimeUpdate); }
private void SpawnCharacter() { charPos = new Point(5, 3); _char = Instantiate(charPrefab, Tiles[charPos].GetComponent <TileScript>().WorldPosition, Quaternion.identity).GetComponent <CharacterControllers>(); }
public SponsorCharacterAI(CharacterControllers characters, in CollidableDescription characterCollidable, in Vector3 initialPosition, in Vector2 targetLocation)
internal void SetCharacterInput(CharacterControllers characterCTs, int bodyHandle, Simulation simulation) { collider.bodyHandle = bodyHandle; characterInput = new CharacterInput(characterCTs, bodyHandle, simulation, this.Position, new Capsule(0.5f, 1f), 0.1f, 1, 20, 100, 6, 4, MathF.PI * 0.4f); }
public CharacterInputSystem(PhysicsSystem physicsSystem, World world) : base(world) { _physicsSystem = physicsSystem; _characters = physicsSystem.Characters; }
public unsafe override void Initialize(ContentArchive content, Camera camera) { camera.Position = new Vector3(20, 10, 20); camera.Yaw = MathF.PI; camera.Pitch = 0; characters = new CharacterControllers(BufferPool); Simulation = Simulation.Create(BufferPool, new CharacterNarrowphaseCallbacks(characters), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0))); CreateCharacter(new Vector3(0, 2, -4)); //Create a bunch of legos to hurt your feet on. var random = new Random(5); var origin = new Vector3(-3f, 0.5f, 0); var spacing = new Vector3(0.5f, 0, -0.5f); for (int i = 0; i < 12; ++i) { for (int j = 0; j < 12; ++j) { var position = origin + new Vector3(i, 0, j) * spacing; var orientation = Quaternion.CreateFromAxisAngle(Vector3.Normalize(new Vector3(0.0001f) + new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble())), 10 * (float)random.NextDouble()); var shape = new Box(0.1f + 0.3f * (float)random.NextDouble(), 0.1f + 0.3f * (float)random.NextDouble(), 0.1f + 0.3f * (float)random.NextDouble()); var collidable = new CollidableDescription(Simulation.Shapes.Add(shape), 0.1f); shape.ComputeInertia(1, out var inertia); var choice = (i + j) % 3; switch (choice) { case 0: Simulation.Bodies.Add(BodyDescription.CreateDynamic(new RigidPose(position, orientation), inertia, collidable, new BodyActivityDescription(0.01f))); break; case 1: Simulation.Bodies.Add(BodyDescription.CreateKinematic(new RigidPose(position, orientation), collidable, new BodyActivityDescription(0.01f))); break; case 2: Simulation.Statics.Add(new StaticDescription(position, orientation, collidable)); break; } } } //Add some spinning fans to get slapped by. var bladeDescription = BodyDescription.CreateConvexDynamic(new Vector3(), 3, Simulation.Shapes, new Box(10, 0.2f, 2)); var bladeBaseDescription = BodyDescription.CreateConvexKinematic(new Vector3(), Simulation.Shapes, new Box(0.2f, 1, 0.2f)); for (int i = 0; i < 3; ++i) { bladeBaseDescription.Pose.Position = new Vector3(-22, 1, i * 11); bladeDescription.Pose.Position = new Vector3(-22, 1.7f, i * 11); var baseHandle = Simulation.Bodies.Add(bladeBaseDescription); var bladeHandle = Simulation.Bodies.Add(bladeDescription); Simulation.Solver.Add(baseHandle, bladeHandle, new Hinge { LocalHingeAxisA = Vector3.UnitY, LocalHingeAxisB = Vector3.UnitY, LocalOffsetA = new Vector3(0, 0.7f, 0), LocalOffsetB = new Vector3(0, 0, 0), SpringSettings = new SpringSettings(30, 1) }); Simulation.Solver.Add(baseHandle, bladeHandle, new AngularAxisMotor { LocalAxisA = Vector3.UnitY, TargetVelocity = (i + 1) * (i + 1) * (i + 1) * (i + 1) * 0.2f, Settings = new MotorSettings(5 * (i + 1), 0.0001f) }); } //Include a giant newt to test character-newt behavior and to ensure thematic consistency. DemoMeshHelper.LoadModel(content, BufferPool, @"Content\newt.obj", new Vector3(15, 15, 15), out var newtMesh); Simulation.Statics.Add(new StaticDescription(new Vector3(0, 0.5f, 0), new CollidableDescription(Simulation.Shapes.Add(newtMesh), 0.1f))); //Give the newt a tongue, I guess. var tongueBase = Simulation.Bodies.Add(BodyDescription.CreateKinematic(new Vector3(0, 8.4f, 24), default, default));