Martin Antonetty
Martin Antonetty

Reputation: 39

sphere collider collid shoot player ship?

Okay, I made some progress with the look towards me I'm able to get the enemy ship to follow the player and the laser guns as well could use some guidance how to get the laser to kill the player ship and prompt the lose and the 'R' for restart messages Aanty insight how to go about it is welcomed.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class EnemyManagement : MonoBehaviour
{
    [SerializeField] GameObject deathFX;
    [SerializeField] Transform parent;
    // The target marker.
    [SerializeField] Transform target;

    // Angular speed in radians per sec.
    [SerializeField] float speed;

    // Start is called before the first frame update
    void Start()
    {
        AddSphereCollider();
    }

    private void AddSphereCollider()
    {
        Collider sphereCollider = gameObject.AddComponent<SphereCollider>();
        sphereCollider.isTrigger = false;
    }

    void Update()
    {
        Vector3 targetDir = target.position - transform.position;

        // The step size is equal to speed times frame time.
        float step = speed * Time.deltaTime;

        Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0f);
        Debug.DrawRay(transform.position, newDir, Color.red);

        // Move our position a step closer to the target.
        transform.rotation = Quaternion.LookRotation(newDir);
    }
}

Upvotes: 1

Views: 89

Answers (1)

AmN
AmN

Reputation: 331

You need to give it a radius for collision detection.

sphereCollider.radius = 10.0f;

Upvotes: 1

Related Questions