public FPRaycastHit Raycast(FPRay ray, FP maxDistance, RaycastCallback callback = null) { IBody hitBody; FPVector hitNormal; FP hitFraction; FPVector origin = ray.origin; FPVector direction = ray.direction; if (Raycast(origin, direction, callback, out hitBody, out hitNormal, out hitFraction)) { if (hitFraction <= maxDistance) { GameObject other = PhysicsManager.instance.GetGameObject(hitBody); FPRigidBody bodyComponent = other.GetComponent <FPRigidBody>(); FPCollider colliderComponent = other.GetComponent <FPCollider>(); FPTransform transformComponent = other.GetComponent <FPTransform>(); return(new FPRaycastHit(bodyComponent, colliderComponent, transformComponent, hitNormal, ray.origin, ray.direction, hitFraction)); } } else { direction *= maxDistance; if (Raycast(origin, direction, callback, out hitBody, out hitNormal, out hitFraction)) { GameObject other = PhysicsManager.instance.GetGameObject(hitBody); FPRigidBody bodyComponent = other.GetComponent <FPRigidBody>(); FPCollider colliderComponent = other.GetComponent <FPCollider>(); FPTransform transformComponent = other.GetComponent <FPTransform>(); return(new FPRaycastHit(bodyComponent, colliderComponent, transformComponent, hitNormal, ray.origin, direction, hitFraction)); } } return(null); }
public FPRaycastHit(FPRigidBody rigidbody, FPCollider collider, FPTransform transform, FPVector normal, FPVector origin, FPVector direction, FP fraction) { this.rigidbody = rigidbody; this.collider = collider; this.transform = transform; this.normal = normal; this.point = origin + direction * fraction; this.distance = fraction * direction.magnitude; }
/** * @brief Creates a new {@link FPRigidBody} when there is no one attached to this GameObject. **/ public void Awake() { FPTransform = this.GetComponent <FPTransform>(); FPRigidBody = this.GetComponent <FPRigidBody>(); if (lossyScale == FPVector.one) { lossyScale = FPVector.Abs(transform.localScale.ToFPVector()); } }
/** * @brief Initializes internal properties based on whether there is a {@link FPCollider} attached. **/ public void Initialize() { if (initialized) { return; } FPCollider = GetComponent <FPCollider>(); if (transform.parent != null) { tsParent = transform.parent.GetComponent <FPTransform>(); } foreach (Transform child in transform) { FPTransform tsChild = child.GetComponent <FPTransform>(); if (tsChild != null) { tsChildren.Add(tsChild); } } if (!_serialized) { UpdateEditMode(); } if (FPCollider != null) { if (FPCollider.IsBodyInitialized) { FPCollider.Body.FPPosition = _position + scaledCenter; FPCollider.Body.FPOrientation = FPMatrix.CreateFromQuaternion(_rotation); } } else { // StateTracker.AddTracking(this); } initialized = true; }
internal void Update(GameObject otherGO, Contact c) { if (this.gameObject == null) { this.gameObject = otherGO; this.collider = this.gameObject.GetComponent <FPCollider>(); this.rigidbody = this.gameObject.GetComponent <FPRigidBody>(); this.transform = this.collider.FPTransform; } if (c != null) { if (contacts[0] == null) { contacts[0] = new FPContactPoint(); } this.relativeVelocity = c.CalculateRelativeVelocity(); contacts[0].normal = c.Normal; contacts[0].point = c.p1; } }
/** * @brief Moves game object based on provided translation vector and a relative {@link FPTransform}. * * The game object will move based on FPTransform's forward vector. **/ public void Translate(FPVector translation, FPTransform relativeTo) { this.position += FPVector.Transform(translation, FPMatrix.CreateFromQuaternion(relativeTo.rotation)); }
/** * @brief Moves game object based on provided axis values and a relative {@link FPTransform}. * * The game object will move based on FPTransform's forward vector. **/ public void Translate(FP x, FP y, FP z, FPTransform relativeTo) { Translate(new FPVector(x, y, z), relativeTo); }
/** * @brief Rotates game object to point forward vector to a target position. * * @param other FPTrasform used to get target position. **/ public void LookAt(FPTransform other) { LookAt(other.position); }