Fairly new to all this, I’ve been converting some script from 3D to 2D, hit a stand still. Was wondering if anyone could assist me. I think that “Quaternion” isn’t compatible with 2D Rigidbody, i’m not looking for just assistance but some sort of explanation too. I get these two error CS1502 and CS1503.
Assets/Scripts/MissleBehaviour.cs(28,31): error CS1502: The best overloaded method match for `UnityEngine.Rigidbody2D.MoveRotation(float)’ has some invalid arguments
Assets/Scripts/MissleBehaviour.cs(28,31): error CS1503: Argument #1' cannot convert
UnityEngine.Quaternion’ expression to type `float’
using UnityEngine;
using System.Collections;
public class MissleBehaviour : MonoBehaviour {
public float missileVelocity = 100;
public float turn = 50;
public Rigidbody2D homingMissile;
public float fuseDelay = 3;
private Transform target;
private float speed = 15;
void Start (){
Fire();
}
void FixedUpdate (){
if(target == null || homingMissile == null)
return;
homingMissile.velocity = transform.forward * missileVelocity;
var targetRotation = Quaternion.LookRotation(target.position - transform.position);
homingMissile.MoveRotation(Quaternion.RotateTowards(transform.rotation, targetRotation, turn));
Destroy (gameObject, 3);
}
void Fire (){
//yield return new WaitForSeconds (fuseDelay);
var distance = Mathf.Infinity;
foreach (var go in GameObject.FindGameObjectsWithTag("target"))
{
var diff = (go.transform.position - transform.position).sqrMagnitude;
if(diff < distance)
{
distance = diff;
target = go.transform;
}
}
}
void OnCollisionEnter (Collision theCollision){
if(theCollision.gameObject.name == "TestEnemy 2")
{
Destroy(gameObject);
}
}
}