Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Paramotion · Jun 04, 2017 at 03:44 PM · transformfloatmonobehaviourcontextexists

transform does not exist in the current context

Just keeping on convert from js to C# the code from Unity, in this script, I'm stuck with the "transform" name.

 using UnityEngine;
 using System.Collections.Generic;
 using System.Collections;
 
 [RequireComponent(typeof(Rigidbody))]
 
 public class FreeMovementMotor : MovementMotor {
     Rigidbody charRigidbody;
     public float walkingSpeed = 5.0f;
     public float walkingSnappyness = 50;
     public float turningSmoothing = 0.3f;
 
     public void Start ()
     {
        // charRigidbody = GetComponent<Rigidbody>();
         
     }
     public void FixedUpdate ()
     {
         //Handle character's movement
         Vector3 targetVelocity = movementDirection * walkingSpeed;
         Vector3 deltaVelocity = targetVelocity - charRigidbody.velocity;
 
         if(charRigidbody.useGravity)
         {
             deltaVelocity.y = 0;
         }
         charRigidbody.AddForce (deltaVelocity * walkingSnappyness, ForceMode.Acceleration);
 
         //Setup player to face facingDirection, or if that's zero, then the movementDirection
         Vector3 faceDir = facingDirection;
 
         if(faceDir == Vector3.zero)
         {
             faceDir = facingDirection;
         }
 
         //Make the character rotate towards the target rotation
         if(faceDir == Vector3.zero)
         {
             charRigidbody.angularVelocity = Vector3.zero;
         }
         else
         {
             float rotationAngle = AngleAroundAxis (transform.forward, faceDir, Vector3.up);
             charRigidbody.angularVelocity = (Vector3.up * rotationAngle * turningSmoothing);
         }
     }
 
     //The angle between dirA and dirB aorund axis
     public static float AngleAroundAxis (Vector3 dirA, Vector3 dirB, Vector3 axis) //CANT BE A VOID!! float??
     {
         //Project A and B onto the plane orthogonal target axis
         dirA = dirA - Vector3.Project (dirA, axis);
         dirB = dirB - Vector3.Project (dirB, axis);
 
         //Find positive angle between A and B
         float angle = Vector3.Angle (dirA, dirB);
 
         //Return angle multiplied with 1 or -1
         return angle * (Vector3.Dot (axis, Vector3.Cross (dirA, dirB)) < 0 ? -1 : 1);
     }
 }
 

in line 45

 float rotationAngle = AngleAroundAxis (transform.forward, faceDir, Vector3.up);

it says "the name "transform" does not exist in the current context [Assembly-CSharp]" Is any way to solve this? Or any advice of why I'm getting this?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by StewVanB · Jun 04, 2017 at 03:54 PM

Are your classes or base classes extending Monobehaviour?

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 Paramotion · Jun 04, 2017 at 08:24 PM 0
Share

No it wasn't extending $$anonymous$$onoBehaviour

 using System;
 using UnityEngine;
 using System.Collections.Generic;
 using System.Collections;
 
 public class $$anonymous$$ovement$$anonymous$$otor
 {
     /*
 This class can be used like an interface.
 Inherit from it to define your own movement motor that can control
 the movement of characters, enemies, or other entities.
 */
 
 // The direction the character wants to move in, in world space.
 // The vector should have a length between 0 and 1.
     public Vector3 movementDirection;
 
 // Simpler motors might want to drive movement based on a target purely    
     public Vector3 movementTarget;
 
 // The direction the character wants to face towards, in world space.    
     public Vector3 facingDirection;
     
 }

in .JS it was like this:

 #pragma strict
 
 /*
 This class can be used like an interface.
 Inherit from it to define your own movement motor that can control
 the movement of characters, enemies, or other entities.
 */
 
 // The direction the character wants to move in, in world space.
 // The vector should have a length between 0 and 1.
 @HideInInspector
 public var movementDirection : Vector3;
 
 // Simpler motors might want to drive movement based on a target purely
 @HideInInspector
 public var movementTarget : Vector3;
 
 // The direction the character wants to face towards, in world space.
 @HideInInspector
 public var facingDirection : Vector3;


So I didn't add "$$anonymous$$ovement$$anonymous$$otor : $$anonymous$$onoBehaviour". I just add it after reading your answer, and it seems to work, thank you!

avatar image
0

Answer by telgo · Feb 06, 2020 at 04:22 PM

Are you still working on the Angry Bots project? We may be able to help each other...

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

78 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What the hell? Cannot convert float to int PROBLEM. 2 Answers

C# round transform.position floats to .5 2 Answers

PlayerStatisticsGUI.cs(Line 27): Error CS0103: The name 'CharTransform' does not exist in the current context (CS0103) (Assembly-CSharp) 2 Answers

Why are floats not accessing my inputted values? 1 Answer

Transform rotation 180° becomes -5.008957e-06? 2 Answers


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