• 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
-1
Question by Jon 3 · May 24, 2010 at 05:27 PM ·

Animation Freezes my movement

i have a 2D platform game with a plane i wanna add animation to, a up and down wards tilt

This is the script im using to make it fly along the X & Y

function Update () {

var x = Input.GetAxis("Horizontal") Time.deltaTime PlayerSpeed;

var y = Input.GetAxis("Vertical") Time.deltaTime PlayerSpeed;

transform.Translate(x, y, 0);

and with my animation script i have this

function Update () { if (Input.GetAxis("Vertical") > 0.2)

animation.CrossFade ("Up");

else

animation.CrossFade ("Idle");

}

i dont know how to add the "Down" with out getting errors.i can only get the up key to work but,my plane then locks it self on position 0,0,0 and i cant move any more the plane will tilt up but thats it? can some one please help me.im a new starter with this java script but im trying to learn and its fustrating me.

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
0

Answer by straydogstrut · May 24, 2010 at 06:31 PM

What errors are you getting? Do you have animations attached to your plane? or (as it looks from the script above) are you trying to simply move the plane when you press the up or down arrows? These are two completely different approaches.

The former should simply be a case of playing the animation as you've done - just make sure you have those animations on the object the animation script is attached to (or reference the correct child object if they're not). It's case-sensitive, so "Up" and "up" are not the same.

function Update ()
{
   if (Input.GetAxis("Vertical") > 0.2)
       animation.CrossFade ("up");
   else
      animation.CrossFade ("idle");
}

For the second approach, there's an example under Input.GetAxis in the scripting docs. Here's a stripped down version that will raise and lower a plane when the up/down arrow keys are pressed. Put this on your plane:

var speed = 10.0;

function Update () {

// Get the vertical axis. // By default this is mapped to the up/down arrow keys. // The value is in the range -1 to 1

var translation = Input.GetAxis ("Vertical") * speed;

// monitor the position (look at the bottom left of game window) Debug.Log(transform.position);

// Make it move in meters per second instead of meters per frame translation *= Time.deltaTime;

// Move translation along the object's y-axis transform.Translate (0, translation, 0);

}

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 Jon 3 · May 24, 2010 at 08:04 PM 0
Share

Yes my plane has animation clips.my plane moves up and down, left and right 2D platform. the player_control script i have works. but when i add the animation_script to add the tilt's to the movement. it locks my plane modle in position 0,0,0. it make the the tilt when i push up but the plane no longer moves. also

function Update() {

if (Input.Get$$anonymous$$ey("w")) animation.Play("Up");

if (Input.Get$$anonymous$$ey("s")) animation.Play("Down");

}

i just tryed this and the play moves up and down with a tilt, but still its, locked on position 0,0,0 in the middle of my screen

avatar image straydogstrut · May 24, 2010 at 09:17 PM 0
Share

When you say "locked on position", do you mean the plane snaps to that position when you press play? Try putting it inside an empty gameObject and setting all it's transforms to zero.

avatar image
0

Answer by Jon 3 · May 24, 2010 at 07:24 PM

Yes my plane has animation clips.my plane moves up and down, left and right 2D platform. the player_control script i have works. but when i add the animation_script to add the tilt's to the movement. it locks my plane modle in position 0,0,0. it make the the tilt when i push up but the plane no longer moves. also

function Update() {

if (Input.GetKey("w")) animation.Play("Up");

if (Input.GetKey("s")) animation.Play("Down");

}

i just tryed this and the play moves up and down with a tilt, but still its, locked on position 0,0,0 in the middle of my screen

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to import the object from server to unity 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Material doesn't have a color property '_Color' 4 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