Photon Bolt Engine API  1.2.7
Properties | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
BoltHitbox Class Reference

Defines one hitbox on a BoltHitboxBody More...

Inheritance diagram for BoltHitbox:

Properties

Vector3 hitboxBoxSize [get, set]
 Size of the hitbox if this shape is a box More...
 
Vector3 hitboxCenter [get, set]
 Center of the hitbox in local coordinates More...
 
BoltHitboxShape hitboxShape [get, set]
 Shape of the hitbox (box or sphere) More...
 
float hitboxSphereRadius [get, set]
 Type of the hitbox More...
 
BoltHitboxType hitboxType [get, set]
 Type of the hitbox More...
 

Private Member Functions

internal void Draw (Matrix4x4 matrix)
 
void OnDrawGizmos ()
 
internal bool OverlapSphere (ref Matrix4x4 matrix, Vector3 center, float radius)
 
bool OverlapSphereOnBox (Vector3 center, float radius)
 
bool OverlapSphereOnSphere (Vector3 center, float radius)
 
internal bool Raycast (ref Matrix4x4 matrix, Vector3 origin, Vector3 direction, out float distance)
 
bool RaycastSphere (Vector3 o, Vector3 d, out float distance)
 

Static Private Member Functions

static void ClampVector (ref Vector3 value, ref Vector3 min, ref Vector3 max, out Vector3 result)
 

Private Attributes

internal Vector3 _boxSize = new Vector3(0.25f, 0.25f, 0.25f)
 
internal Vector3 _center = Vector3.zero
 
internal BoltHitboxShape _shape = BoltHitboxShape.Box
 
internal float _sphereRadius = 0.25f
 
internal BoltHitboxType _type = BoltHitboxType.Unknown
 

Detailed Description

Defines one hitbox on a BoltHitboxBody

Example: Resizing a sphere hitbox

void ResizeSphereHitbox(BoltHitbox hitbox, float newRadius) {
if(hitbox.hitboxShape != BoltHitboxShape.Sphere) {
Debug.Log("Attemping to resize a non-sphere hitbox");
return;
}
hitbox.hitboxSphereRadius = newRadius;
}

Member Function Documentation

◆ ClampVector()

static void BoltHitbox.ClampVector ( ref Vector3  value,
ref Vector3  min,
ref Vector3  max,
out Vector3  result 
)
inlinestaticprivate

◆ Draw()

internal void BoltHitbox.Draw ( Matrix4x4  matrix)
inlineprivate

◆ OnDrawGizmos()

void BoltHitbox.OnDrawGizmos ( )
inlineprivate

◆ OverlapSphere()

internal bool BoltHitbox.OverlapSphere ( ref Matrix4x4  matrix,
Vector3  center,
float  radius 
)
inlineprivate

◆ OverlapSphereOnBox()

bool BoltHitbox.OverlapSphereOnBox ( Vector3  center,
float  radius 
)
inlineprivate

◆ OverlapSphereOnSphere()

bool BoltHitbox.OverlapSphereOnSphere ( Vector3  center,
float  radius 
)
inlineprivate

◆ Raycast()

internal bool BoltHitbox.Raycast ( ref Matrix4x4  matrix,
Vector3  origin,
Vector3  direction,
out float  distance 
)
inlineprivate

◆ RaycastSphere()

bool BoltHitbox.RaycastSphere ( Vector3  o,
Vector3  d,
out float  distance 
)
inlineprivate

Member Data Documentation

◆ _boxSize

internal Vector3 BoltHitbox._boxSize = new Vector3(0.25f, 0.25f, 0.25f)
private

◆ _center

internal Vector3 BoltHitbox._center = Vector3.zero
private

◆ _shape

internal BoltHitboxShape BoltHitbox._shape = BoltHitboxShape.Box
private

◆ _sphereRadius

internal float BoltHitbox._sphereRadius = 0.25f
private

◆ _type

internal BoltHitboxType BoltHitbox._type = BoltHitboxType.Unknown
private

Property Documentation

◆ hitboxBoxSize

Vector3 BoltHitbox.hitboxBoxSize
getset

Size of the hitbox if this shape is a box

Example: A method to double the size of a player's head hitbox if it is a box.

void DoubleHeadSize(BoltHitboxBody body) {
foreach(BoltHitbox hitbox in body.hitboxes) {
if(hitbox.hitboxType == BoltHitboxType.Head) {
hitbox.hitboxBoxSize = hitbox.hitboxBoxSize * 2f;
}
}
}

◆ hitboxCenter

Vector3 BoltHitbox.hitboxCenter
getset

Center of the hitbox in local coordinates

Example: Getting a vector that points from the player's weapon to the head of a target entity.

Vector3 GetHeadshotVector(BoltEntity target, IWeapon currentWeapon) {
BoltHitboxBody body = target.GetComponent<BoltHitboxBody%gt();
BoltHitbox head = body.hitboxes[0];
foreach(BoltHitbox hitbox in body.hitboxes) {
if(hitbox.hitboxType == BoltHitboxType.Head) {
head = hitbox;
}
}
return head.hitboxCenter - currentWeapon.fireOrigin;
}

◆ hitboxShape

BoltHitboxShape BoltHitbox.hitboxShape
getset

Shape of the hitbox (box or sphere)

Example: Sorting the hitboxes in a body based on shape.

void ConfigureHitboxes(BoltHitboxBody body) {
foreach(BoltHitbox hitbox in body.hitboxes) {
switch(hitbox.hitboxShape) {
case BoltHitboxShape.Sphere: ConfigureSphere(hitbox); break;
case BoltHitboxShape.Box: ConfigureBox(hitbox); break;
}
}
}

◆ hitboxSphereRadius

float BoltHitbox.hitboxSphereRadius
getset

Type of the hitbox

Example: A method to double the size of a player's head hitbox if it is a sphere.

void DoubleHeadSize(BoltHitboxBody body) {
foreach(BoltHitbox hitbox in body.hitboxes) {
if(hitbox.hitboxType == BoltHitboxType.Head) {
hitbox.hitboxSphereRadius = hitbox.hitboxSphereRadius * 2f;
}
}
}

◆ hitboxType

BoltHitboxType BoltHitbox.hitboxType
getset

Type of the hitbox

Example: Modifying a base damage value depending on the area of the hit.

float CalculateDamage(BoltHitbox hit, float baseDamage) {
switch(hit.hitboxType) {
case BoltHitboxType.Head: return 2.0f * baseDamage;
case BoltHitboxType.Leg:
case BoltHitboxType.UpperArm: return 0.7f * baseDamage;
default: return baseDamage;
}
}