public void SetPlayerVelocity(float2 vel) { VelocityData velData = ManagerProvider.GetEntityManager.GetComponentData <VelocityData>(PlayerEntity.Entity); velData.Velocity = vel; ManagerProvider.GetEntityManager.SetComponentData(PlayerEntity.Entity, velData); }
public override object Read(string path) { var rawData = new VelocityData(); string txt; using (var reader = new StreamReader(path)) { txt = reader.ReadToEnd(); } var grammar = new OpenFoamGrammar(); var parser = new Parser(grammar); var tree = parser.Parse(txt); foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null)) { var identifier = rootEntryNode.GetEntryIdentifier(); switch (identifier) { //case "turbineArrayOn": // rawData.TurbineArrayOn = rootEntryNode.GetBasicValBool(); // break; } } return rawData; }
public override object Read(string path) { var rawData = new VelocityData(); string txt; using (var reader = new StreamReader(path)) { txt = reader.ReadToEnd(); } var grammar = new OpenFoamGrammar(); var parser = new Parser(grammar); var tree = parser.Parse(txt); foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null)) { var identifier = rootEntryNode.GetEntryIdentifier(); switch (identifier) { //case "turbineArrayOn": // rawData.TurbineArrayOn = rootEntryNode.GetBasicValBool(); // break; } } return(rawData); }
public void SetCameraMaxSpeed(string input) { VelocityData velData = ManagerProvider.GetEntityManager.GetComponentData <VelocityData>(CameraEntity.Entity); float maxSpeed = float.Parse(MaxSpeedInput.Camera.text); velData.MaxSpeed = maxSpeed; ManagerProvider.GetEntityManager.SetComponentData(CameraEntity.Entity, velData); }
void OnTriggerPulled(object someSender, TriggerPulledEventArgs e) { IEntity player = this.DataCenter.GetEntitiesWithTag("Player").Single(); SpatialData playerSpatial = player.GetData <SpatialData> (); VelocityData playerVelocity = player.GetData <VelocityData> (); IEntity projectile = this.DataCenter.CreateEntity(); projectile.Tag = "Projectile"; Vector2 pos = new Vector2(playerSpatial.X, playerSpatial.Y); projectile.AddData( new SpatialData() { X = pos.X, Y = pos.Y, Rotation = playerSpatial.Rotation } ); float rotationRads = (float)(Math.PI / 180.0) * playerSpatial.Rotation; Vector2 vPlayer = new Vector2(playerVelocity.X, playerVelocity.Y); Vector2 v = new Vector2( (float)Math.Cos(rotationRads) * this.ProjectileSpeed, (float)Math.Sin(rotationRads) * this.ProjectileSpeed ); /*float angle = * Vector2.Dot( v, vPlayer ) * / ( v.LengthFast * vPlayer.LengthFast ); * float arcX = angle; * float arcY = (float)Math.Sin( Math.Acos( angle ) );*/ projectile.AddData( new VelocityData() { X = v.X, //+ ( arcX * playerVelocity.X ), Y = v.Y //+ ( arcY * playerVelocity.Y ) } ); projectile.AddData( new ShapeData( 10, new List <Vector2> () { new Vector2(0, 0), new Vector2(0, -0.25f), new Vector2(0.75f, -0.5f), new Vector2(1, 0), new Vector2(0.75f, 0.5f), new Vector2(0, 0.25f), } ) ); }
public void Execute(int index) { float2 controllerPos = new float2(ControllerPos.x, ControllerPos.y); VelocityData data = new VelocityData(); data.Velocity = controllerPos - BigControllerPos; data.MaxSpeed = Speed; Velocities[index] = data; }
public void FillVelocityData(VelocityData velocityData) { if (velocityData == null) { throw new ArgumentNullException("velocityData"); } double speed = this.NorthVelocity * this.NorthVelocity + this.EastVelocity * this.EastVelocity; velocityData.SpeedMs = Math.Sqrt(speed); }
private void SetVelocity(int index) { float2 position = new float2(Positions[index].Value.x, Positions[index].Value.y); float2 target = Targets[index].Value; VelocityData data = new VelocityData(); data.Velocity = math.normalize(target - position); data.MaxSpeed = MaxSpeed; // Velocities[index] = data; EntityBuffer.SetComponent(index, EntityArray[index], data); }
protected override void buildInteractionData(IImpactObject target, TCollision collision, TContact contactPoint, VelocityData myVelocityData, VelocityData otherVelocityData, ImpactTagMask?tagMask, float compositionValue) { Vector3 relativeContactPointVelocity = myVelocityData.TotalPointVelocity - otherVelocityData.TotalPointVelocity; if (SlideMode != SlideMode.None) { InteractionData slideParameters = new InteractionData() { TagMask = tagMask, Point = contactPoint.Point, Normal = contactPoint.Normal, Velocity = relativeContactPointVelocity, InteractionType = InteractionData.InteractionTypeSlide, ThisObject = contactPoint.ThisObject, OtherObject = contactPoint.OtherObject, CompositionValue = compositionValue }; invokeTriggeredEvent(slideParameters, target); ImpactManagerInstance.ProcessContinuousInteraction(slideParameters, target); } if (RollMode != RollMode.None) { float roll = 1 - Mathf.Clamp01(relativeContactPointVelocity.magnitude * 0.1f); if (roll > 0) { Vector3 rollVelocity = myVelocityData.TangentialVelocity * roll; InteractionData rollParameters = new InteractionData() { TagMask = tagMask, Point = contactPoint.Point, Normal = contactPoint.Normal, Velocity = rollVelocity, InteractionType = InteractionData.InteractionTypeRoll, ThisObject = contactPoint.ThisObject, OtherObject = contactPoint.OtherObject, CompositionValue = compositionValue }; invokeTriggeredEvent(rollParameters, target); ImpactManagerInstance.ProcessContinuousInteraction(rollParameters, target); } } }
public void Execute() { VelocityData data = new VelocityData(); data.Velocity = new float2(0, 0); data.MaxSpeed = CameraVel.MaxSpeed; if (InRect) { data.Velocity = PlayerVel.Velocity; } // EntityBuffer.SetComponent(Entity, data); }
public static VelocityData StopRigidVelocity(Rigidbody2D rigid) { VelocityData data = new VelocityData(); data.velocity = rigid.velocity; data.angularVelocity = rigid.angularVelocity; data.isKinematic = rigid.isKinematic; rigid.velocity = Vector2.zero; rigid.angularVelocity = 0f; rigid.isKinematic = true; return(data); }
/// <summary> /// Process a collision contact to get all material and velocity data. /// The material and velocity data will be sent to buildInteractionData, which you can override. /// </summary> /// <param name="collision">The original collision data.</param> /// <param name="contactPoint">The contact point of the collision to use in calculations.</param> protected void processCollisionContact(TCollision collision, TContact contactPoint) { IImpactObject myObject = getImpactObject(contactPoint.ThisObject); if (myObject != null) { IImpactObject otherObject = contactPoint.OtherObject.GetComponentInParent <IImpactObject>(); bool hasOtherObject = otherObject != null; //Material composition is enabled if (UseMaterialComposition && hasOtherObject) { //Get material composition int count = otherObject.GetMaterialCompositionNonAlloc(contactPoint.Point, ImpactManagerInstance.MaterialCompositionBuffer); //Get velocity data VelocityData myVelocityData = myObject.GetVelocityDataAtPoint(contactPoint.Point); VelocityData otherVelocityData = otherObject.GetVelocityDataAtPoint(contactPoint.Point); //Create interaction for each material for (int i = 0; i < count; i++) { ImpactMaterialComposition comp = ImpactManagerInstance.MaterialCompositionBuffer[i]; if (comp.CompositionValue > 0) { buildInteractionData(myObject, collision, contactPoint, myVelocityData, otherVelocityData, comp.Material.MaterialTagsMask, comp.CompositionValue); } } } //Material composition is not enabled else { //Get velocity data VelocityData otherVelocityData = hasOtherObject ? otherObject.GetVelocityDataAtPoint(contactPoint.Point) : new VelocityData(); VelocityData myVelocityData = myObject.GetVelocityDataAtPoint(contactPoint.Point); //Get tag mask ImpactTagMask?tagMask = getOtherObjectTagMask(otherObject, contactPoint.Point, contactPoint.OtherPhysicsMaterialID, hasOtherObject); //Create interaction buildInteractionData(myObject, collision, contactPoint, myVelocityData, otherVelocityData, tagMask, 1); } } else { //Impact object could not be found. MainTarget is not assigned and no Impact Object could be determined from the contact point. Debug.LogError("Unable to find Impact Object on GameObject " + gameObject.name); } }
public void Execute(int index) { Steering steering = new Steering(); steering.MaxSpeed = MaxArriveSpeed; float2 sourcePos = new float2(SmallControllerPos[index].Value.x, SmallControllerPos[index].Value.y); float2 sourceVel = Velocities[index].Velocity; float2 targetPos = GetTargetPos(sourcePos); float2 desireVelosity = steering.Arrive(sourcePos, targetPos, SlowingRadius); VelocityData data = new VelocityData(); data.MaxSpeed = MaxSpeed; data.Velocity = desireVelosity; Velocities[index] = data; }
public void Execute(int i) { //calculate acceleration //get distance to center var squareDistanceToCenter = Util.SquareDistance(positions[i].Value, new float3()); var directionToCenter = -positions[i].Value; var normalizedVectorToCenter = directionToCenter / Mathf.Sqrt(squareDistanceToCenter); var acceleration = (400.0f / Mathf.Max(squareDistanceToCenter, 5.0f)) * normalizedVectorToCenter; //calculate velocity: v = u + at velocities[i] = new VelocityData { Value = velocities[i].Value + acceleration * deltaTime }; //calculate new position - only velocity term: s = s' + vt positions[i] = new Position { Value = positions[i].Value + velocities[i].Value * deltaTime }; }
protected override void buildInteractionData(IImpactObject target, TCollision collision, TContact contactPoint, VelocityData myVelocityData, VelocityData otherVelocityData, ImpactTagMask?tagMask, float CompositionValue) { Vector3 relativeContactPointVelocity = myVelocityData.TotalPointVelocity - otherVelocityData.TotalPointVelocity; InteractionData interactionData = new InteractionData() { TagMask = tagMask, Point = contactPoint.Point, Normal = contactPoint.Normal, Velocity = relativeContactPointVelocity, InteractionType = InteractionData.InteractionTypeCollision, ThisObject = contactPoint.ThisObject, OtherObject = contactPoint.OtherObject, CompositionValue = CompositionValue }; invokeTriggeredEvent(interactionData, target); ImpactManagerInstance.ProcessInteraction(interactionData, target); }
protected override void buildInteractionData(IImpactObject target, ImpactCollisionWrapper collision, ImpactContactPoint contactPoint, VelocityData myVelocityData, VelocityData otherVelocityData, ImpactTagMask?tagMask, float CompositionValue) { VelocityData currentVelocityData = rigidbodyWrapper.GetCurrentVelocityData(contactPoint.Point); Vector3 velocityChange = myVelocityData.TotalPointVelocity - currentVelocityData.TotalPointVelocity; Vector3 relativeContactPointVelocity = myVelocityData.TotalPointVelocity - otherVelocityData.TotalPointVelocity; InteractionData interactionData = new InteractionData() { TagMask = tagMask, Point = contactPoint.Point, Normal = contactPoint.Normal, Velocity = Vector3.Lerp(relativeContactPointVelocity, velocityChange, _velocityChangeInfluence), InteractionType = InteractionData.InteractionTypeCollision, ThisObject = contactPoint.ThisObject, OtherObject = contactPoint.OtherObject, CompositionValue = CompositionValue }; invokeTriggeredEvent(interactionData, target); ImpactManagerInstance.ProcessInteraction(interactionData, target); }
public void Write(GamePacketWriter writer) { VelocityData.Write(writer); writer.Write(Blend); }
public void Read(GamePacketReader reader) { VelocityData.Read(reader); Blend = reader.ReadBit(); }
public static void RestoreRigidVelocity(Rigidbody2D rigid, VelocityData data) { rigid.velocity = data.velocity; rigid.angularVelocity = data.angularVelocity; rigid.isKinematic = data.isKinematic; }
private void processParticleCollision(ParticleCollisionEvent particleCollisionEvent, GameObject onParticleCollisionObject, bool isParticleSystem) { IImpactObject myObject; //Particle system always uses the main target if (isParticleSystem) { myObject = MainTarget; } //Non-particle system gets the object from the particle collision event's collider else { myObject = getImpactObject(particleCollisionEvent.colliderComponent.gameObject); } if (myObject != null) { IImpactObject otherObject = null; //Get other object based on whether or not this object is a particle system if (isParticleSystem) { otherObject = particleCollisionEvent.colliderComponent.GetComponentInParent <IImpactObject>(); } else { otherObject = onParticleCollisionObject.GetComponentInParent <IImpactObject>(); } bool hasOtherObject = otherObject != null; if (UseMaterialComposition && hasOtherObject) { int count = otherObject.GetMaterialCompositionNonAlloc(particleCollisionEvent.intersection, ImpactManagerInstance.MaterialCompositionBuffer); //Velocity data is dependent on if this is a particle system or a not VelocityData myVelocityData; VelocityData otherVelocityData; if (isParticleSystem) { myVelocityData = new VelocityData(particleCollisionEvent.velocity, Vector3.zero); otherVelocityData = otherObject.GetVelocityDataAtPoint(particleCollisionEvent.intersection); } else { myVelocityData = myObject.GetVelocityDataAtPoint(particleCollisionEvent.intersection); otherVelocityData = new VelocityData(particleCollisionEvent.velocity, Vector3.zero); } Vector3 relativeContactPointVelocity = myVelocityData.TotalPointVelocity - otherVelocityData.TotalPointVelocity; for (int i = 0; i < count; i++) { ImpactMaterialComposition comp = ImpactManagerInstance.MaterialCompositionBuffer[i]; if (comp.CompositionValue > 0) { InteractionData interactionData = new InteractionData() { TagMask = comp.Material.MaterialTagsMask, Point = particleCollisionEvent.intersection, Normal = particleCollisionEvent.normal, Velocity = relativeContactPointVelocity, InteractionType = InteractionData.InteractionTypeCollision, ThisObject = this.gameObject, OtherObject = otherObject.GameObject, CompositionValue = 1f }; invokeTriggeredEvent(interactionData, myObject); ImpactManagerInstance.ProcessInteraction(interactionData, myObject); } } } else { //Velocity data is dependent on if this is a particle system or a not VelocityData myVelocityData; VelocityData otherVelocityData; if (isParticleSystem) { myVelocityData = new VelocityData(particleCollisionEvent.velocity, Vector3.zero); otherVelocityData = hasOtherObject ? otherObject.GetVelocityDataAtPoint(particleCollisionEvent.intersection) : new VelocityData(); } else { myVelocityData = myObject.GetVelocityDataAtPoint(particleCollisionEvent.intersection); otherVelocityData = new VelocityData(particleCollisionEvent.velocity, Vector3.zero); } Vector3 relativeContactPointVelocity = myVelocityData.TotalPointVelocity - otherVelocityData.TotalPointVelocity; //Get physics material ID for material mapping, but only if this object is a particle system. //Particles don't have a collider so no need to try and get the physics material if this is not a particle system int otherPhysicsMaterialID = isParticleSystem ? getPhysicsMaterialID(particleCollisionEvent.colliderComponent) : 0; ImpactTagMask?tagMask = getOtherObjectTagMask(otherObject, particleCollisionEvent.intersection, otherPhysicsMaterialID, hasOtherObject); InteractionData interactionData = new InteractionData() { TagMask = tagMask, Point = particleCollisionEvent.intersection, Normal = particleCollisionEvent.normal, Velocity = relativeContactPointVelocity, InteractionType = InteractionData.InteractionTypeCollision, ThisObject = this.gameObject, OtherObject = particleCollisionEvent.colliderComponent.gameObject, CompositionValue = 1f }; invokeTriggeredEvent(interactionData, myObject); ImpactManagerInstance.ProcessInteraction(interactionData, myObject); } } else { Debug.LogError("Unable to find Impact Object on GameObject " + gameObject.name); } }
public GpxData(PositionData positionData, VelocityData velocityData, PrecisionData precisionData) { this.PositionData = positionData; this.PrecisionData = precisionData; this.VelocityData = velocityData; }
/// <summary> /// Called by the process methods to build IInteractionData. /// Override this if your custom triggers are using any of the process methods. /// </summary> /// <param name="target">The target IImpactObject to send data to. You do not necessarily have to send data to this object.</param> /// <param name="collision">The collision being processed.</param> /// <param name="contactPoint">The collision contact point.</param> /// <param name="myVelocityData">The velocity data of this object.</param> /// <param name="otherVelocityData">The velocity data of the object being collided with.</param> /// <param name="tagMask">The tag mask obtained from the other object. Can be null.</param> /// <param name="compositionValue">The material composition value.</param> protected virtual void buildInteractionData(IImpactObject target, TCollision collision, TContact contactPoint, VelocityData myVelocityData, VelocityData otherVelocityData, ImpactTagMask?tagMask, float compositionValue) { }