Lighting hitting enemy ?

Example

here is my lighting.

How to pointing lighting to hit enemy (moving) if he gets close to me (player).

Lightning*

As with any flashy game effect, there is an invisible collider doing the actual damage.
If your question is about auto-targeting the lightning however, really depends on how you are generating this lightning effect right now.

1 Like

Add sphere collider to your player or a range, then when an enemy player collides to the sphere collider call the prefab lightning and instantiate that to the enemy’s position and add offset to cast it from above.

1 Like

This mean, my lighting will not work as the way on the example picture. I have to add two objects and play lighting between them. Good.

Like this script:

    public Transform _enemy;
    public Transform _player;
    private GameObject _lighting; // prefab
    private Vector3 offset;

    void Start ()    {
        _lighting = GameObject.FindGameObjectWithTag("light") as GameObject;

    }

    public void Update()    {
        offset = new Vector3 (_enemy.transform.position.x,_enemy.transform.position.y,_enemy.transform.position.z);

        if (Input.GetKey(KeyCode.Space)) {
            Instantiate(_lighting, offset, Quaternion.identity);
        }

    }

Lightning**

There is literally no difference between the two lines below

offset = new Vector3 (_enemy.transform.position.x,_enemy.transform.position.y,_enemy.transform.position.z);
offset = enemy.transform.position

The way your lightning effect works in your script looks like it’s coming from above, as opposed to your example which comes from the caster. Is that your intention?

You need to add the enemy’s position to the offset variable so that the position of lightning will be adjusted. Something just like this.

_enemy.transform.position = _enemy.transform.position + offset;

be sure to add a value for the offset.