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 propro2000 · Oct 25, 2013 at 11:56 AM · movement scriptrotate objectmove an object

Two problems One code

When I run this code I get two problems, the most serious one is an error: Assets/Scripts/AI.js(26,46): BCE0017: The best overload for the method 'UnityEngine.Quaternion.Slerp(UnityEngine.Quaternion, UnityEngine.Quaternion, float)' is not compatible with the argument list '(UnityEngine.Vector3, UnityEngine.Quaternion, float)'.

The next, if I comment out the 26th line and when I move the player closer to the capsule object I attached the script too it gets another error: NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) AI.Attack () (at Assets/Scripts/AI.js:30) AI.Update () (at Assets/Scripts/AI.js:20)

The code:

 var Distance;
 var Target : Transform;
 var LookAtDistance = 25.0;
 var attackRange = 15.0;
 var movespeed = 6.0;
 var Damping = 4.0;
 
 function Update() {
     Distance = Vector3.Distance(Target.position, transform.position);
     
     if(Distance < LookAtDistance) {
         renderer.material.color = Color.yellow;
         LookAt();
         }
     if(Distance > LookAtDistance) {
         renderer.material.color = Color.green;
     }
     if(Distance < attackRange) {
         renderer.material.color = Color.red;
         Attack();
     }
 }
 
 function LookAt() {
     var rotation = Quaternion.LookRotation(Target.position - transform.position);
     //transform.rotation = Quaternion.Slerp(transform.position, rotation, Time.deltaTime * Damping);
 }
 
 function Attack() {
     transform.Translate(Vector3.foward * movespeed * Time.deltaTime);
 }

Could anyone please help me with these problems? Thanks in advance.

Comment
Add comment · Show 2
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 meat5000 ♦ · Oct 25, 2013 at 12:00 PM 1
Share

Quaternion is a rotation. You need a start rotation, end rotation and a scaling factor (0 to 1) for Q.slerp

Your error says you are inputting a Vector3 ins$$anonymous$$d.

(UnityEngine.Vector3, UnityEngine.Quaternion, float)

A NullReferenceEception occurs when something can't be found, like an object.

You have

 var Target : Transform;

but it's an empty container specifying variable type but not filling it wil viable information. "I see its a Transform but the Transform of What?"

avatar image ArkaneX · Oct 25, 2013 at 12:02 PM 1
Share

Did you copy and paste the code? If it is copied, then in line 30 you should have Vector3.forward, not Vector3.foward

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by propro2000 · Oct 26, 2013 at 07:02 AM

Thanks for the help guys. Here is finished (Mostly) script for anyone who has trouble.\

 var Distance;
 var Target : Transform;
 var Player : GameObject;
 var LookAtDistance = 50.0;
 var ChaseRange = 15.0;
 var AttackRange = 3.0;
 var movespeed = 6.0;
 var Damping = 4.0;
 var damamount = 124;
 
 var attackrepeattime = 2;
 private var attacktime : float;
 
 var Controller : CharacterController;
 var Gravity : float = 20.0;
 private var MoveDirection : Vector3 = Vector3.zero;
 private var maxSpeed = movespeed;
 
 var idleanimation : AnimationClip;
 var attackanimation : AnimationClip;
 var walkanimation : AnimationClip;
 var dieanimation : AnimationClip; 
 
 function Start() {
     attacktime = Time.time;
 }
 
 function Update() {
     Distance = Vector3.Distance(Target.position, transform.position);
     
     if(Distance < LookAtDistance) {
         LookAt();
         }
     if(Distance > LookAtDistance) {
         animation.Play(idleanimation.name);
     }
     if (Distance < AttackRange) {
         Attack();
     }
     else if(Distance < ChaseRange) {
             Chase();
     }
 }
 
 function LookAt() {
     if(animation.isPlaying == false) {
         animation.Play(idleanimation.name);
     }
     var relativePos = Target.position - transform.position;
     var rotation = Quaternion.LookRotation(relativePos);
     transform.rotation = rotation;
 }
 
 function Chase() {
     if( Distance > AttackRange) {
     animation.Play(walkanimation.name);
     movespeed = maxSpeed;
     }
     MoveDirection = transform.forward;
     MoveDirection *= movespeed;
     
     MoveDirection.y -= Gravity * Time.deltaTime;
     Controller.Move(MoveDirection * Time.deltaTime);
 }
 
 
 function Attack() {
     if(Time.time > attacktime) {
         animation.Play(attackanimation.name);
         Player.BroadcastMessage("TakeDamage", damamount);
         attacktime = Time.time + attackrepeattime;
     }
 }
 
 function ApplyDamage() {
     LookAtDistance += LookAtDistance / 5;
     ChaseRange += ChaseRange / 5;
     movespeed += movespeed / 5;
     damamount += damamount / 10;
 }
Comment
Add comment · 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

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

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Helicoper Movement Help 1 Answer

How to flip, on click a constant moving 2d rigidbody on the x-axis and maintain speed? 0 Answers

Dodge movement - restrict movement of an object left and right 0 Answers

How can I make a prefab object from a list to move?,How can I make an object from a list to move by itself? 2 Answers

How can I add a delay between moving objects ? 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