Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

unity overlapbox

//don't forget to divide radius by half. in my case, it was:
Collider[] colliders = Physics.OverlapBox(position, boxCollider.size /2);

//https://docs.unity3d.com/ScriptReference/Physics.OverlapBox.html
Comment

unity overlap box

//draw a hitbox in front of the character to see which objects it collides with
Vector3 boxPosition = transform.position + (Vector3.up * lastAttack.collHeight) 
        + Vector3.right * lastAttack.collDistance;
Vector3 boxSize = new Vector3 (lastAttack.CollSize/2, lastAttack.CollSize/2, hitZRange/2);
Collider[] hitColliders = Physics.OverlapBox(boxPosition, boxSize,
        transform.rotation, HitLayerMask);

...

void OnDrawGizmos(){
    if (lastAttack != null && (Time.time - lastAttackTime) < lastAttack.duration) {

        // cache previous Gizmos settings
        Color prevColor = Gizmos.color;
        Matrix4x4 prevMatrix = Gismos.matrix;

        Gizmos.color = Color.red;
        Gizmos.matrix = transform.localToWorldMatrix; 

        Vector3 boxPosition = transform.position + (Vector3.up * lastAttack.collHeight) 
                + Vector3.right * ((int)lastAttackDirection * lastAttack.collDistance);

        // convert from world position to local position 
        boxPosition = transform.InverseTransformPoint(boxPosition); 

        Vector3 boxSize = new Vector3 (lastAttack.CollSize, lastAttack.CollSize, hitZRange); 
        Gizmos.DrawWireCube (boxPosition, boxSize);

        // restore previous Gizmos settings
        Gizmos.color = prevColor;
        Gizmos.matrix = prevMatrix;
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Beep sound Javascript 
Javascript :: using settings_data.json shopify 
Javascript :: javascript page loader 
Javascript :: run promise one by one 
Javascript :: activate router angular 
Javascript :: how to change a sting into js code 
Javascript :: KeyboardDatePicker background color 
Javascript :: esx global error 
Javascript :: scraping google nodejs 
Javascript :: freenom 
Javascript :: "npm supertest 
Javascript :: destruction in javascript 
Python :: python create new folder if not exist 
Python :: python shebang 
Python :: save a dict to pickle 
Python :: show all columns pandas 
Python :: vowel and consonant list python 
Python :: unique values in pyspark column 
Python :: '.join([chr((ord(flag[i]) &lt;&lt; 8) + ord(flag[i + 1])) for i in range(0, len(flag), 2)]) 
Python :: python check is os is windows 
Python :: python copy paste file 
Python :: python mkdir 
Python :: imshow grayscale 
Python :: how to simulate a key press in python 
Python :: EnvironmentError command line 
Python :: python loop through all folders and subfolders 
Python :: install python-dev packages 
Python :: Extract images from html page based on src attribute using beatutiful soup 
Python :: python log with timestamp 
Python :: python run server 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =