• 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 john 2 · Aug 19, 2010 at 06:02 PM · errorsyntax-errorbce0005

jumping error!?

i am making a 2d platformer that involves jumping but when i put my code in it gives me this error: Unknown identifier moveDirection. but i know it should a known identifier because it's highlighted orange!

my script:

var jumpSpeed = 5.0;

if(Input.GetKeyDown("UpArrow"))

{

moveDirection.y = jumpSpeed;

}

p.s. please help!

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

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Eric5h5 · Aug 19, 2010 at 07:20 PM

It's unknown because you haven't defined it anywhere. You need to define variables before you can use them.

Comment
Add comment · Show 2 · 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 john 2 · Aug 19, 2010 at 07:35 PM 0
Share

what do i need to put in after i type var moveDirection = ? if i put a number it comes up with an error.please comment back! thanks!

avatar image TenKHoursDev · Nov 23, 2018 at 01:19 AM 0
Share

You need to use datatypes instead of the generic 'var'. It's good practice and will help you hone your skills. But you said you need a direction so you ought to write "var moveDirection = new vector3(x, y,z);"

avatar image
0

Answer by Statement · Dec 10, 2010 at 09:05 PM

Try this.

var jumpSpeed = 5.0; var moveDirection : Vector3;

if(Input.GetKeyDown("UpArrow")) { moveDirection.y = jumpSpeed; }

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

Answer by FallingRocketGames · Nov 23, 2018 at 02:00 AM

I believe you should be approaching this issue in a different way, I recommend you to use AddForce and study a little about the Rigidbody2d component in your Player, also check about ForceMode like Impulse. https://docs.unity3d.com/ScriptReference/Rigidbody2D.AddForce.html https://docs.unity3d.com/ScriptReference/ForceMode2D.html

  public float Speed;
  void FixedUpdate()
  {
 
      if (Input.GetKey(KeyCode.Space))
      {
 
          GetComponent<Rigidbody2D>().AddForce(Vector2.up* Speed);
      }
  }
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
avatar image
0

Answer by LearningWhileScrewing · Nov 23, 2018 at 04:11 AM

var jumpSpeed = 5.0; var moveDirection Vector2; if(Input.GetKeyDown("UpArrow"))

{

moveDirection.y = jumpSpeed;

} //this is javascript, so not good at javascript // lower 1 is c# //============ public float jumpSpeed; public Rigidbody2D rb2d; void Start() { rb2d = GetComponent(); }

void Update() {

   if (Input.GetKey("up"))
   {
      Vector2 movement = new Vector2(0, 5);
       if(movement != Vector2.zero) {
       rb2d.AddForce(movement * jumpSpeed);

} } }

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Can't compile script from Scripting Tutorial (translated to Boo) 3 Answers

I have an error while building the game 1 Answer

I got a major question 1 Answer

Unexpected Token: Collider. 1 Answer

What does BCE0004: Ambiguous reference error mean? 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges