Trying to get enemy to aim at the player and shoot at it

Here’s my code (I use Javascript):

	#pragma strict
	//Find Player
	var Target : Transform;
	//Projectile itself
	var projectile: Rigidbody2D;
	var seconds : float = 5;
	var projectileSpeed : float = 5;
	var fire : boolean;

	function fireAtPlayer(){
			fire = true;
			yield WaitForSeconds(seconds);
			fire = false;
			yield WaitForSeconds(seconds);

	function shoot(){
			var clone = Instantiate(projectile, transform.position, transform.rotation);
			clone.velocity = rigidbody2D.AddForce(transform.forward * projectileSpeed);

	function Start () {

	function Update () {

I get this error:
Line 22 :Cannot convert void to UnityEngine.Vector2

I’m kinda new to programming so

void means he doesnt recognise the function as a vector2 type

take off pragma strict.

use transform lookat.

read turret tutorials.

google turret tutorial tornado.

The error is because the function rigidbody2D.AddForce(); doesn’t return a value but you are trying to use it to set the velocity of the clone.

Instead if you want to add the velocity to the clone object you could do this.


Presuming it has a rigidbody attached.

The AddForce function automatically alters the velocity of the rigidbody so you don’t have to do the assignment.