Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by junkdog8 · Jan 28, 2015 at 08:22 PM · c#errorai

stupid errors i can't figure out

hey guys, i am trying to get this enemy AI for A* to work with my custom character controller, but i am getting a few stupid errors that i have tried several different ways to fix but i cannot get it.

the problem seems to be with the direction the player is supposed to be moving in.

here is the code

 using UnityEngine;
 using System.Collections;
 using Pathfinding;
 
 [RequireComponent (typeof (Rigidbody2D))]
 [RequireComponent (typeof (Seeker))]
 public class EnemyAI : MonoBehaviour
 {
 
     // What to chase?
     public Transform target;
     
     // How many times each second we will update our path
     public float updateRate = 2f;
 
     //enemy effect played on destruction
     public GameObject DestroyedEffect;
 
     // Caching
     private Seeker seeker;
     private Rigidbody2D rb;
     
     //The calculated path
     public Path path;
     
     //The AI's movement
     public float Speed;
     private float _normalizedDirection;
     private Vector2 _direction;
     private Vector2 _startPosition;
     private CharacterController2D _controller;
     
     [HideInInspector]
     public bool pathIsEnded = false;
     
     // The max distance from the AI to a waypoint for it to continue to the next waypoint
     public float nextWaypointDistance = 3;
     
     // The waypoint we are currently moving towards
     private int currentWaypoint = 0;
     
     void Start ()
     {
         _normalizedDirection = (path.vectorPath[currentWaypoint] - _startPosition).normalized;
         _controller = GetComponent<CharacterController2D> ();
         _startPosition = transform.position;
         _direction = new Vector2(_normalizedDirection, 0);
         seeker = GetComponent<Seeker>();
         rb = GetComponent<Rigidbody2D>();
         
         if (target == null) {
             Debug.LogError ("No Player found? PANIC!");
             return;
         }
         
         // Start a new path to the target position, return the result to the OnPathComplete method
         seeker.StartPath (transform.position, target.position, OnPathComplete);
         
         StartCoroutine (UpdatePath ());
     }
     
     IEnumerator UpdatePath () {
         if (target == null) {
             //TODO: Insert a player search here.
             return false;
         }
         
         // Start a new path to the target position, return the result to the OnPathComplete method
         seeker.StartPath (transform.position, target.position, OnPathComplete);
         
         yield return new WaitForSeconds ( 1f/updateRate );
         StartCoroutine (UpdatePath());
     }
     
     public void OnPathComplete (Path p) {
         Debug.Log ("We got a path. Did it have an error? " + p.error);
         if (!p.error) {
             path = p;
             currentWaypoint = 0;
         }
     }
     
     void FixedUpdate () {
         if (target == null) {
             //TODO: Insert a player search here.
             return;
         }
         
         //TODO: Always look at player?
         
         if (path == null)
             return;
         
         if (currentWaypoint >= path.vectorPath.Count) {
             if (pathIsEnded)
                 return;
             
             Debug.Log ("End of path reached.");
             pathIsEnded = true;
             return;
         }
         pathIsEnded = false;
     
         //Direction to the next waypoint
         //Vector3 dir = ( path.vectorPath[currentWaypoint] - transform.position ).normalized;
         
         //Move the AI
          _controller.SetHorizontalForce(_direction.x * Speed);
         
         float dist = Vector3.Distance (transform.position, path.vectorPath[currentWaypoint]);
         if (dist < nextWaypointDistance) {
             currentWaypoint++;
             return;
         }
     }
     
 }


here are the errors

 Assets/Scripts/EnemyAI.cs(44,46): error CS0121: The call is ambiguous between the following methods or properties: `UnityEngine.Vector2.operator -(UnityEngine.Vector2, UnityEngine.Vector2)' and `UnityEngine.Vector3.operator -(UnityEngine.Vector3, UnityEngine.Vector3)'
 
 Assets/Scripts/EnemyAI.cs(44,17): error CS0029: Cannot implicitly convert type `UnityEngine.Vector3' to `float'


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Jan 28, 2015 at 08:22 PM

 private float _normalizedDirection;

How can "normalized direction" be a float? Did you mean:

 private Vector3 _normalizedDirection;
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image junkdog8 · Jan 28, 2015 at 09:24 PM 0
Share
 that changes the errors to ones i had before
 
     Assets/Scripts/EnemyAI.cs(44,46): error CS0121: The call is ambiguous between the following methods or properties: `UnityEngine.Vector2.operator -(UnityEngine.Vector2, UnityEngine.Vector2)' and `UnityEngine.Vector3.operator -(UnityEngine.Vector3, UnityEngine.Vector3)'
     
     
     Assets/Scripts/EnemyAI.cs(47,66): error CS1502: The best overloaded method match for `UnityEngine.Vector2.Vector2(float, float)' has some invalid arguments
     
     
     Assets/Scripts/EnemyAI.cs(47,66): error CS1503: Argument `#1' cannot convert `UnityEngine.Vector3' expression to type `float'
     
 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Need help calling a variable from another C# script 1 Answer

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

In game log not working. 2 Answers

Argument out of range. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges