本文整理汇总了C#中BoxCollider.Intersects方法的典型用法代码示例。如果您正苦于以下问题:C# BoxCollider.Intersects方法的具体用法?C# BoxCollider.Intersects怎么用?C# BoxCollider.Intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoxCollider
的用法示例。
在下文中一共展示了BoxCollider.Intersects方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
protected override void Update(TimeSpan gameTime)
{
touchPanelState = WaveServices.Input.TouchPanelState;
bestValue = float.MaxValue;
if (touchPanelState.IsConnected && touchPanelState.Count > 0)
{
// Calculate the ray
CalculateRay();
// Look for all entities in the game...
for (int i = 0; i < EntityManager.Count; i++)
{
currentEntity = EntityManager.EntityGraph.ElementAt(i); ;
entityCollider = currentEntity.FindComponent<BoxCollider>();
// ... but only a collidable entities ( entities which have a boxCollider component)
if (entityCollider != null)
{
// Intersect our calculated ray with the entity's boxCollider
collisionResult = entityCollider.Intersects(ref ray);
// If any collision
if (collisionResult.HasValue)
{
// Check the distance. We want to have the closer to the screen entity, so we want to get the low collisionResult value
if (collisionResult.Value < bestValue)
{
// Send to the scene the new entity picked name
(WaveServices.ScreenContextManager.CurrentContext[0] as MyScene).ShowPickedEntity(currentEntity.Name);
bestValue = collisionResult.Value;
}
}
}
}
}
else
{
(WaveServices.ScreenContextManager.CurrentContext[0] as MyScene).ShowPickedEntity("None");
}
}
示例2: Update
protected override void Update(TimeSpan gameTime)
{
touchPanelState = WaveServices.Input.TouchPanelState;
if (touchPanelState.IsConnected && touchPanelState.Count > 0)
{
// Calculate the ray
CalculateRay();
// Look for all entities in the game...
Entity auxEntity = currentEntity = null;
bestValue = float.MaxValue;
for (int i = 0; i < EntityManager.Count; i++)
{
auxEntity = EntityManager.EntityGraph.ElementAt(i);
entityCollider = auxEntity.FindComponent<BoxCollider>();
// ... but only a collidable entities ( entities which have a boxCollider component)
if (entityCollider != null && ( auxEntity.Name.Contains("box") ||
auxEntity.Name.Contains("anchor") ||
auxEntity.Name.Contains("BigBall")) )
{
// Intersect our calculated ray with the entity's boxCollider
collisionResult = entityCollider.Intersects(ref ray);
// If any collision
if (collisionResult.HasValue && collisionResult.Value > 0.001f)
{
//Labels.Add("CollisionResult", collisionResult.ToString());
//Labels.Add("CollisionValue", collisionResult.Value.ToString());
// Check the distance. We want to have the closer to the screen entity, so we want to get the low collisionResult value
if (collisionResult.Value < bestValue)
{
this.currentEntity = auxEntity;
bestValue = collisionResult.Value;
}
}
}
}
if (this.currentEntity != null)
{
Vector3 entityPosition = this.currentEntity.FindComponent<Transform3D>().Position;
Vector3 impulse = entityPosition - this.Camera.Position;
this.currentEntity.FindComponent<RigidBody3D>().ApplyLinearImpulse(impulse*FORCE);
this.line.StartPoint = ray.Position;
this.line.EndPoint = entityPosition;
Labels.Add("Entity", this.currentEntity.Name);
//Labels.Add("Impulse", impulse.ToString());
//Labels.Add("IsActive", this.currentEntity.FindComponent<RigidBody3D>().IsActive.ToString());
}
else
{
Labels.Add("Entity", "None");
//Labels.Add("Impulse", "0,0,0");
}
}
//RenderManager.LineBatch3D.DrawLine(ref line);
//RenderManager.LineBatch3D.DrawLine(ref line2);
}