Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Player Special Effects | Player Behavior
Fighting Game in Unity

bookPlayer Special Effects

RaycastHit2D.point

RaycastHit2D.point is a property in Unity used to retrieve the world space position where a 2D raycast hit an object's collider.

So, RaycastHit2D.point allows you to access the precise location where a 2D raycast makes contact with an object's collider, which is useful for performing actions or calculations based on the collision point.

In our case, we have used it to get the point of the attack of the enemy and play the particles at that point.

Placing Particles

if (isAttacking)
{
    RaycastHit2D rayCastHit = Physics2D.Raycast(transform.position, Vector2.right * transform.localScale.x, range, enemyLayer);
    if (rayCastHit)
    {
        attackEffect.transform.position = rayCastHit.point;
        attackEffect.Play();
        isAttacking = false;
    }
}

After adding the particle as a child of our player, we will create a SerializeField for our particle and drag and drop it.

To play the particle, we need to set up its position, and we choose the raycast hit position for it.

So after changing its position to raycastHit.point, we will call Play() on the particles, so they start playing in the game and show us the visuals and the impact.

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 4

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Awesome!

Completion rate improved to 3.33

bookPlayer Special Effects

Veeg om het menu te tonen

RaycastHit2D.point

RaycastHit2D.point is a property in Unity used to retrieve the world space position where a 2D raycast hit an object's collider.

So, RaycastHit2D.point allows you to access the precise location where a 2D raycast makes contact with an object's collider, which is useful for performing actions or calculations based on the collision point.

In our case, we have used it to get the point of the attack of the enemy and play the particles at that point.

Placing Particles

if (isAttacking)
{
    RaycastHit2D rayCastHit = Physics2D.Raycast(transform.position, Vector2.right * transform.localScale.x, range, enemyLayer);
    if (rayCastHit)
    {
        attackEffect.transform.position = rayCastHit.point;
        attackEffect.Play();
        isAttacking = false;
    }
}

After adding the particle as a child of our player, we will create a SerializeField for our particle and drag and drop it.

To play the particle, we need to set up its position, and we choose the raycast hit position for it.

So after changing its position to raycastHit.point, we will call Play() on the particles, so they start playing in the game and show us the visuals and the impact.

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 4
some-alt