本文整理汇总了C#中ContactPoint类的典型用法代码示例。如果您正苦于以下问题:C# ContactPoint类的具体用法?C# ContactPoint怎么用?C# ContactPoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContactPoint类属于命名空间,在下文中一共展示了ContactPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnCollisionEnter
//Raugh version
void OnCollisionEnter(Collision collision)
{
foreach (ContactPoint contact in collision.contacts) {
finalContact = contact;
}
collision.rigidbody.AddForce(finalContact.normal * bouncyness);
}
示例2: SwitchDirection
/* we need to determine what direction we collided with environment so we can change direction.
* we check first and last point in the collection and determine what pieces of the vector positions match
* and then flip horizontal/vertical while maintaining the opposite movement (vertical/horizontal respectively)
*/
void SwitchDirection(ContactPoint[] hits)
{
// InverseTransformPoint will convert to local space so we can easily tell where it is in relation to us
Vector3 relativePosition1 = transform.InverseTransformPoint(hits[0].point);
Vector3 relativePosition2 = transform.InverseTransformPoint(hits[hits.Length - 1].point);
if (relativePosition1.x > 0 && relativePosition2.x > 0) // right
{
if (currentDirection == "NE") currentDirection = "NW";
if (currentDirection == "SE") currentDirection = "SW";
GetComponent<tk2dSprite>().FlipX = true;
}
if (relativePosition1.x < 0 && relativePosition2.x < 0) // left
{
if (currentDirection == "NW") currentDirection = "NE";
if (currentDirection == "SW") currentDirection = "SE";
GetComponent<tk2dSprite>().FlipX = false;
}
if (relativePosition1.y > 0 && relativePosition2.y > 0) // up
{
if (currentDirection == "NE") currentDirection = "SE";
if (currentDirection == "NW") currentDirection = "SW";
}
if (relativePosition1.y < 0 && relativePosition2.y < 0) // down
{
if (currentDirection == "SE") currentDirection = "NE";
if (currentDirection == "SW") currentDirection = "NW";
}
}
示例3: Explode
void Explode(ContactPoint[] contacts)
{
gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
gameObject.GetComponent<Renderer>().enabled = false;
if(halo != null)
{
halo.GetType().GetProperty("enabled").SetValue(halo, false, null);
}
Destroy(gameObject, ProjectileDeathTimer);//Kind of hacky, can modify to use the time property in the trail system.
}
示例4: ShowDustParticles
public void ShowDustParticles(ContactPoint contactPoint)
{
if (contactPoint.point != null)
{
// Place Particle Effect where it hits the ground
GameObject gObj = Instantiate(PFX_HittingGround);
gObj.transform.position = contactPoint.point;
// Play Hitting Sand Sound
int soundNum = Random.Range (0,2);
if(soundNum == 0) GetComponent<SoundsTriggered>().playSound2(true, 1);
else if (soundNum == 1) GetComponent<SoundsTriggered>().playSound3(true, 1);
}
}
示例5: ProcessBuffPackage
private void ProcessBuffPackage(ContactPoint contact, PackageType buffType)
{
TankHealth healthComponent = contact.otherCollider.GetComponent<TankHealth>();
TankMovement movementComponent = contact.otherCollider.GetComponent<TankMovement>();
switch (buffType)
{
case PackageType.Health:
healthComponent.Heal(m_HealthBenefit);
break;
case PackageType.Speed:
movementComponent.m_HasSpeedBuff = true;
break;
default:
break;
}
}
示例6: In
public void In(
[FriendlyName("ContactPoint", "The ContactPoint to randomly choose from. Connect a ContactPoint List or individual ContactPoint variables to this socket.")]
ContactPoint[] ObjectSet,
[FriendlyName("Target ContactPoint", "The ContactPoint value that gets set.")]
out ContactPoint Target
)
{
if (ObjectSet == null)
{
Target = new ContactPoint();
return;
}
int index = Random.Range(0, ObjectSet.Length);
Target = ObjectSet[index];
}
示例7: In
public void In(
[FriendlyName("Value", "The variable you wish to use to set the target's value.")]
object Value,
[FriendlyName("Target", "The Target variable you wish to set.")]
out ContactPoint Target
)
{
if ( Value.GetType() != typeof(ContactPoint) )
{
uScriptDebug.Log( "Set ContactPoint: Value is not a ContactPoint!", uScriptDebug.Type.Error );
Target = new ContactPoint( );
}
else
{
Target = (ContactPoint) Value;
}
}
示例8: LaunchBall
public void LaunchBall(ContactPoint cp, bool platformFlag)
{
this.StopTheBall();
this.BallRigRef.freezeRotation = false;
Vector3 newDir = Vector3.zero;
Vector3 curDir = this.BallRigRef.transform.TransformDirection(Vector3.forward);
float differenceBetweenContactAndCenter = cp.point.x - this.gameObject.transform.position.x;
if (platformFlag) //hit the platform
{
if (Mathf.Abs(differenceBetweenContactAndCenter) < 0.1f) // presuming it hit the center
{
newDir = Vector3.Reflect(curDir, cp.normal);
LaunchBallStraight(newDir, curDir);
this.BallRigRef.freezeRotation = true;
}
else // hit the side
{
float modifier = 60.0f * differenceBetweenContactAndCenter;
GameObject.Find("RotationDummy").transform.Rotate(0.0f, modifier, 0.0f);
Quaternion targetRotation = GameObject.Find("RotationDummy").transform.rotation;
this.BallRigRef.transform.rotation = targetRotation;
Vector3 targVector = this.BallRigRef.transform.TransformDirection(Vector3.forward);
this.BallRigRef.AddForce(targVector * this.thrust);
this.BallRigRef.freezeRotation = true;
GameObject.Find("RotationDummy").transform.rotation = Quaternion.identity;
}
}
else // hit something else
{
newDir = Vector3.Reflect(curDir, cp.normal);
if (this.CheckForStraightAngleBug(newDir))
{
Vector3 tmpDir = new Vector3(newDir.x + (Random.Range(0.5f, 1.5f) - 1.0f), 0.0f, (Random.Range(0.5f, 1.5f) - 1.0f));
newDir = tmpDir;
}
LaunchBallStraight(newDir, curDir);
this.BallRigRef.freezeRotation = true;
}
this.lastCp = cp;
}
示例9: Explode
void Explode(ContactPoint[] contacts)
{
GameObject explosion = Instantiate(explosionPrefab, contacts[0].point, Quaternion.identity) as GameObject;
Destroy(explosion, ExplosionDeathTimer);
for (int i = -5; i <= 5; ++i)
{
for (int j = -5; j <= 5; ++j)
{
for (int k = -5; k <= 5; ++k)
{
RaycastHit hit;
Ray ray = new Ray(transform.position, new Vector3(i, j, k));
Physics.Raycast(ray, out hit);
Rigidbody body = hit.rigidbody;
if (body != null)
{
Vector3 direction = body.transform.position - transform.position;
direction = direction.normalized;
body.AddForce(direction * ExplosionStrength);
Health hp = body.gameObject.GetComponent<Health>();
if(hp != null)
{
hp.TakeDamage(damage);
}
//if(body.gameObject.tag != "Player" && body.gameObject.tag != "Projectile")
// Destroy(body.gameObject, 1.0f);
}
}
}
}
gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
gameObject.GetComponent<Rigidbody>().isKinematic = true;
gameObject.GetComponent<Renderer>().enabled = false;
Destroy(gameObject, ProjectileDeathTimer);
}
示例10: AddCollider
public void AddCollider(uint localID, ContactPoint contact)
{
if (!m_objCollisionList.ContainsKey(localID))
{
m_objCollisionList.Add(localID, contact);
}
else
{
if (m_objCollisionList[localID].PenetrationDepth < contact.PenetrationDepth)
m_objCollisionList[localID] = contact;
}
}
示例11: AddCollisionEvent
public void AddCollisionEvent(uint CollidedWith, ContactPoint contact)
{
CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
}
示例12: AddCollisionEvent
internal void AddCollisionEvent(uint CollidedWith, ContactPoint contact)
{
if (m_eventsubscription > 0)
{
// m_log.DebugFormat(
// "[PHYSICS]: Adding collision event for {0}, collidedWith {1}, contact {2}", "", CollidedWith, contact);
CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
}
}
示例13: AddCollisionEvent
public void AddCollisionEvent(uint CollidedWith, ContactPoint contact)
{
if (CollisionEventsThisFrame == null)
CollisionEventsThisFrame = new CollisionEventUpdate();
CollisionEventsThisFrame.addCollider(CollidedWith, contact);
}
示例14: AddCollisionEvent
public override void AddCollisionEvent (uint CollidedWith, ContactPoint contact)
{
if (base.SubscribedToCollisions () && SubscribedEvents())//If we don't have anything that we are going to trigger, don't even add
{
if (CollisionEventsThisFrame == null)
CollisionEventsThisFrame = new CollisionEventUpdate ();
CollisionEventsThisFrame.addCollider (CollidedWith, contact);
}
}
示例15: CallOnCollisionContactEnter
/*
* \brief Works out if a value is almost another value (for floating point accuracy)
*/
public void CallOnCollisionContactEnter(ContactPoint contact)
{
// check the normal to see if the collision is in the horizontal plain
if (!m_colliding && (contact.normal.y < 0.1 && contact.normal.y > -0.1))
{
m_velocity = 0.0f;
m_colliding = true;
}
}