public override void CollisionEvent(PhysicObject sender, EventArgs p) { PhysicObject obj = (PhysicObject)sender; //Debug.WriteLine("Here"); obj.CollisionUp.UpdateColisions(); }
public override void DisturbedEvent(PhysicObject sender, PhysicObject p) { if (sender is Hero && p is Enemies) { sender.StartMovingProcess.UpdateMovement.Suspend(); } }
public void ReceiveContact(PhysicObject obj, RaycastHit2D hit) { //hit from top, we DIE if (hit.normal.y > 0.8f) { Die(); //TODO : find a better way of detecting player PlayerController playerInput = obj.GetComponent <PlayerController>(); if (playerInput != null) { Vector2 velocity = obj.velocity; velocity.y = playerInput.jumpTakeoffSpeed * 0.5f; obj.SetVelocity(velocity); } } else if (Mathf.Abs(hit.normal.x) > 0.9f) { PlayerData data = obj.GetComponent <PlayerData>(); if (data != null) { data.Damaged(1, hit.normal); } } }
public void ReactCollision(ref List <RaycastHit2D> contacts) { List <GameObject> handledObject = new List <GameObject>(); for (int i = 0; i < contacts.Count; ++i) { if (contacts[i].collider != null && contacts[i].collider.gameObject.name != "taggedToDelete") { int layer = contacts[i].collider.gameObject.layer; if (layer == m_enemyLayers) { contacts.RemoveAt(i); i--; } else { PhysicObject obj = contacts[i].collider.GetComponent <PhysicObject>(); if (obj != null) { if (Mathf.Abs(contacts[i].normal.x) > 0.8f) {//pushing m_pushing = true; m_pushingTimer = 0.2f; obj.velocity = Vector2.Scale(m_po.velocity, Vector2.right); } } } } } }
public override void DisturbedEvent(PhysicObject sender, PhysicObject p) { sender.InMoment.NegMoment(); sender.InBattle = true; p.InBattle = true; p.InMoment.NegMoment(); p.InBattle = true; }
protected virtual void Awake() { _forward = spriteFaceLeft ? Vector2.left : Vector2.right; _animator = GetComponent <Animator>(); _spriteRenderer = GetComponent <SpriteRenderer>(); _po = GetComponent <PhysicObject>(); }
private void Awake() { _animator = GetComponent <Animator>(); _physicObject = GetComponent <PhysicObject>(); _playerController = GetComponent <PlayerController>(); SceneLinkedSMB <PlayerData> .Initialise(_animator, this); }
private void Start() { _physicObject = GetComponent <PhysicObject>(); _rigidbody = GetComponent <Rigidbody>(); OtherPlayer = GameObject.FindGameObjectWithTag("Player1"); Physics.IgnoreCollision(OtherPlayer.GetComponent <Collider>(), GetComponent <Collider>()); OtherPlayer = GameObject.FindGameObjectWithTag("Player2"); Physics.IgnoreCollision(OtherPlayer.GetComponent <Collider>(), GetComponent <Collider>()); }
public override void DisturbedEvent(PhysicObject sender, PhysicObject p) { Canvas c1 = this.Container; Canvas c2 = c1.Parent as Canvas; Canvas c3 = c2.Parent as Canvas; Page p2 = c3.Parent as Page; p.MinimumObjectInteractive = sender; p2.Frame.Navigate(typeof(Battle), p); }
public override void DisturbedEvent(PhysicObject sender, PhysicObject physicObject) { StackPanel s = new StackPanel(); //s.Children.Add(ImageView.ImageSet()); TextBlock t = new TextBlock() { Text = "NPC", }; s.Children.Add(t); Flt.Content = s; FlyoutBase.SetAttachedFlyout(sender.Container, Flt); FlyoutBase.ShowAttachedFlyout(sender.Container); }
void OnEnable() { _renderer = GetComponentInChildren <SpriteRenderer>(); _renderer.color = Color.white; _animator = GetComponent <Animator>(); _po = GetComponent <PhysicObject>(); if (_po != null) { _po.inputCallback += HandleInput; _po.collisionCallback += ReactCollision; } }
public void UpdatePhysics(PhysicObject objectID, Vector3 position, Vector3 rotation, Vector3 velocity, float angularVelocity) { //double test = 0; /*if (!mCurrentInstance.IsServer()) { test = EngineManager.CLIENT_DELAY_TIME; }*/ //if (mCurrentInstance.IsServer()) //{ //NewEventAllRemote(mCurrentInstance.GetEngineTime() + test, "DoObjectFunction", objectID, "DoUpdate", position, scale, rotation, velocity, angularVelocity); NewObjectEventAllRemote(objectID, "DoUpdate", position, rotation, velocity, angularVelocity); //} }
public override void DisturbedEvent(PhysicObject sender, PhysicObject p) { StackPanel s = new StackPanel(); s.Children.Add(ImageView.ImageSet(Item.Path)); TextBlock t = new TextBlock() { Text = "Click E to add to you inventory", }; s.Children.Add(t); Fl.Content = s; FlyoutBase.SetAttachedFlyout(p.Container, Fl); FlyoutBase.ShowAttachedFlyout(p.Container); }
private void ResetScene() { List <PhysicObject> toBeRemoved = new List <PhysicObject>(); foreach (GameComponent gc in this.Components) { if (gc is PhysicObject && !(gc is HeightmapObject) && !(gc is CarObject) && !(gc is TriangleMeshObject) && !(gc is PlaneObject)) { PhysicObject physObj = gc as PhysicObject; toBeRemoved.Add(physObj); } } foreach (PhysicObject physObj in toBeRemoved) { physObj.PhysicsBody.DisableBody(); this.Components.Remove(physObj); //seems to be very important. Hold one of the demo keys and //watch your memory. physObj.Dispose(); } int count = physicSystem.Controllers.Count; for (int i = 0; i < count; i++) { physicSystem.Controllers[0].DisableController(); } count = physicSystem.Constraints.Count; for (int i = 0; i < count; i++) { physicSystem.RemoveConstraint(physicSystem.Constraints[0]); } //count = physicSystem.Constraints.Count; //for (int i = 0; i < count; i++) // physicSystem.Controllers[0].DisableController(); //count = physicSystem.Constraints.Count; //for (int i = 0; i < count; i++) // physicSystem.Constraints[0].DisableConstraint; }
/// <summary> /// Called after object is added to the world. /// </summary> protected virtual void AfterAddedToTheWorld() { if (PhysicObject != null) { PhysicObject.afterAdded(this); } if (Modelo != null) { Modelo.afterAdded(this); } if (Material != null) { Material.AfterAdded(this); } }
private PhysicObject SpawnPrimitive(Vector3 pos, Matrix ori) { var prim = random.Next(3); var a = 1.0f + (float)random.NextDouble() * 1.0f; var b = a + (float)random.NextDouble() * 0.5f; var c = 2.0f / a / b; PhysicObject physicObj = prim switch { 0 => new BoxObject(this, boxModel, new Vector3(a, b, c), ori, pos), 1 => new SphereObject(this, sphereModel, 0.5f, ori, pos), 2 => new CapsuleObject(this, capsuleModel, 0.5f, 1f, ori, pos), _ => new SphereObject(this, sphereModel, random.Next(5, 15), ori, pos) }; return(physicObj); }
//This needs to be OnRecievedID, or something void Start() { PhysicObject tempObject = gameObject.GetComponent<PhysicObject>(); if (tempObject != null) { mThisManager = tempObject.GetInstance(); if (tempObject.GetInstance().GetSyncedClient() != null) { int objectID = tempObject.GetObjectID(); tempObject = tempObject.GetInstance().GetSyncedClient().GetObject<PhysicObject>(objectID); mSyncedObject = tempObject.transform; mSyncedPhysics = tempObject; mSyncedPathing = tempObject.GetComponent<Pathing>(); mSyncedRigidbody = tempObject.rigidbody2D; } } }
void AddNewGameObject(GameObject obj) { Vector3 massCenterDelta; float objVolume = EvaluateObjectVolume(obj, out massCenterDelta); var newPhysicObject = new PhysicObject { gao = obj, volume = objVolume, massCenterDelta = massCenterDelta }; bool addPhysicObject = true; for (int i = 0; i < physicObjects.Count; i++) { foreach (var effect in physicEffects) { addPhysicObject &= effect.OnFluidSimContact(this, physicObjects[i]); } } if (addPhysicObject) { physicObjects.Add(newPhysicObject); } }
protected override void Update(GameTime gameTime) { KeyboardState keyState = Keyboard.GetState(); MouseState mouseState = Mouse.GetState(); if (keyState.IsKeyDown(Keys.Escape)) { this.Exit(); } #region Picking Objects with the mouse if (mouseState.MiddleButton == ButtonState.Pressed) { if (middleButton == false) { Vector3 ray = RayTo(mouseState.X, mouseState.Y); float frac; CollisionSkin skin; Vector3 pos, normal; ImmovableSkinPredicate pred = new ImmovableSkinPredicate(); physicSystem.CollisionSystem.SegmentIntersect(out frac, out skin, out pos, out normal, new Segment(camera.Position, ray * 1000.0f), pred); if (skin != null && (skin.Owner != null)) { if (!skin.Owner.Immovable) { Vector3 delta = pos - skin.Owner.Position; delta = Vector3.Transform(delta, Matrix.Transpose(skin.Owner.Orientation)); camPickDistance = (camera.Position - pos).Length(); oldWheel = mouseState.ScrollWheelValue; skin.Owner.SetActive(); objectController.Destroy(); damperController.Destroy(); objectController.Initialise(skin.Owner, delta, pos); damperController.Initialise(skin.Owner, ConstraintVelocity.ReferenceFrame.Body, Vector3.Zero, Vector3.Zero); objectController.EnableConstraint(); damperController.EnableConstraint(); } } middleButton = true; } if (objectController.IsConstraintEnabled && (objectController.Body != null)) { Vector3 delta = objectController.Body.Position - camera.Position; Vector3 ray = RayTo(mouseState.X, mouseState.Y); ray.Normalize(); float deltaWheel = mouseState.ScrollWheelValue - oldWheel; camPickDistance += deltaWheel * 0.01f; Vector3 result = camera.Position + camPickDistance * ray; oldWheel = mouseState.ScrollWheelValue; objectController.WorldPosition = result; objectController.Body.SetActive(); } } else { objectController.DisableConstraint(); damperController.DisableConstraint(); middleButton = false; } #endregion if (mouseState.LeftButton == ButtonState.Pressed && leftButton == false) { PhysicObject physObj = SpawnPrimitive(camera.Position, Matrix.CreateRotationX(0.5f)); physObj.PhysicsBody.Velocity = (camera.Target - camera.Position) * 20.0f; Components.Add(physObj); leftButton = true; } if (mouseState.LeftButton == ButtonState.Released) { leftButton = false; } Keys[] pressedKeys = keyState.GetPressedKeys(); if (pressedKeys.Length != 0) { switch (pressedKeys[0]) { case Keys.D1: ResetScene(); CreateScene1(9); break; case Keys.D2: ResetScene(); CreateScene2(); break; case Keys.D3: ResetScene(); CreateScene3(); break; case Keys.D4: ResetScene(); CreateScene4(12); break; case Keys.D5: ResetScene(); CreateScene5(20); break; case Keys.D6: ResetScene(); CreateScene6(); break; case Keys.D7: ResetScene(); CreateScene7(); break; case Keys.D8: ResetScene(); CreateScene8(); break; case Keys.D9: ResetScene(); CreateScene9(); break; case Keys.D0: ResetScene(); CreateScene0(); break; } } debugDrawer.Enabled = keyState.IsKeyDown(Keys.C); if (keyState.IsKeyDown(Keys.Up) || keyState.IsKeyDown(Keys.Down)) { if (keyState.IsKeyDown(Keys.Up)) { carObject.Car.Accelerate = 1.0f; } else { carObject.Car.Accelerate = -1.0f; } } else { carObject.Car.Accelerate = 0.0f; } if (keyState.IsKeyDown(Keys.Left) || keyState.IsKeyDown(Keys.Right)) { if (keyState.IsKeyDown(Keys.Left)) { carObject.Car.Steer = 1.0f; } else { carObject.Car.Steer = -1.0f; } } else { carObject.Car.Steer = 0.0f; } if (keyState.IsKeyDown(Keys.B)) { carObject.Car.HBrake = 1.0f; } else { carObject.Car.HBrake = 0.0f; } if (singleStep == true && keyState.IsKeyDown(Keys.Space) == false) { // don't intergrate so we can step at will } else { float timeStep = (float)gameTime.ElapsedGameTime.Ticks / TimeSpan.TicksPerSecond; if (timeStep < 1.0f / 60.0f) { physicSystem.Integrate(timeStep); } else { physicSystem.Integrate(1.0f / 60.0f); } } base.Update(gameTime); }
void Start() { direction = gameObject.transform.up; _programmedDeath = Time.realtimeSinceStartup + lifeSpan; _po = GetComponent <PhysicObject>(); }
public Collision(List <PhysicObject> array, PhysicObject p) { this.array = array; this.p = p; }
public override void OnDisturberd(PhysicObject p, PhysicObject obj) { InterationEvent?.DynamicInvoke(obj, p); }
public static void BattleManagerFunc(PhysicObject hero, PhysicObject enemie) { }