UDEngine.Core.Collision

UDEngine.Core.Collision implements the colliders and collision callbacks. Comparing to the native colliders and triggers of Unity3D, UDEngine.Core.Collision is much more performant over thousands of moving bullets. As a trade-off, though, it lacks the capability of handling any kind of physics, and that bullets are required to have a collider shape of (currently) only circles. (nevertheless, most bullet-hell games require no complicated physics anyways, and that simple physics, such as bouncing, could be simulated with special handling in user-defined callbacks)

UCollisionMonitor

UCollisionMonitor is a centralized handler of all bullet collisions (with targets, borders, or regional triggers). Each scene MUST have its own UCollisionMonitor attached to some GameObject.

Properties

shouldUpdate

public bool shouldUpdate

Should Update() of the monitor run. If false, all collision detection and callback invocation will be stopped.

In Update(), we found

if (!shouldUpdate) {
    return;
}

bound...

public float boundXMin;
public float boundWidth;
public float boundYMin;
public float boundHeight;

Define the border. Every bullet collider that goes outside of the border would have their boundary callbacks invoked.

In the Unity3D inspector, you will see the customized editor that draws the border on screen.

Methods

IsInBoundary

public bool IsInBoundary(Vector3 pos) {}
public bool IsInBoundary(Vector2 pos) {}

Check if the given position is inside monitor's boundary.

It is intended for private use, but you can also use it for your own checks. Just notice that position.z won't work in UDEngine, as we will always assume that position.z == 0.

Get/Set/Remove/Clear...Collider/Trigger[s]

public LinkedList<UBulletCollider> GetBulletColliders() {}
public List<UTargetCollider> GetTargetColliders() {}
public List<IBulletRegionTrigger> GetBulletRegionTriggers() {}

public void AddBulletCollider(UBulletCollider collider) {}
public void AddTargetCollider(UTargetCollider collider) {}
public void AddBulletRegionTrigger(IBulletRegionTrigger trigger) {}

public void ClearBulletColliders() {}
public void ClearTargetColliders() {}
public void ClearBulletRegionTriggers() {}

public void RemoveBulletCollider(UBulletCollider collider) {}
public void RemoveTargetCollider(UTargetCollider collider) {}
public void RemoveBulletRegionTrigger(IBulletRegionTrigger trigger) {}

Get, set, remove, and clear respective colliders.

Targets are what bullets are aimed at, e.g. players. This also implies we allow multiple targets exist in the same scene.
BulletRegionTriggers are regional trigger colliders for bullets.

As simple as explained in their names. However, one part to notice is that Remove...() methods are slow and should be avoided if possible.

GetTargetPosition

public Vector3 GetTargetPosition(int index = 0) {}

Get target position by index at this frame. The index would be based on the sequence where you AddTargetCollider().

You would want to use this method if you have thousands of bullets need to check this value, e.g. in the case of aiming player. As the value is internally cached each frame, we avoid the terrible overhead created by Transform.position.

SetUpdate

public void SetUpdate(bool condition = true) {}

Turn on and off the update handling.

On SetUpdate(false), collision detection and callback handling would all stop.

UCircleCollider

UCircleCollider is the base class of UTargetCollider and UBulletCollider. It implements the IUCollider interface.

Properties & Methods

radius

public float radius = 1f;
public float GetRadius() {}
public void SetRadius(float radius) {}

Radius of the circle collider, getter and setter.

Simple.

trans

public Transform trans;
public Transform GetTransform() {}
public void SetTransform(Transform trans) {}

Transform where position, etc. of the collider are based on.

The transform is usually set to be the transform of the gameobject where UBulletObject is on.

layer

public int layer;
public int GetLayer() {}
public void SetLayer(int layer) {}

Layers, similar to the native physics layer in Unity3D, that objects on different layers would ignore each other's collision and collision callbacks.

I actually forgot to implement it. I will do a one-line fix right away.

results matching ""

    No results matching ""