• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Xedfire 1 · Apr 01, 2011 at 03:39 PM · animation2dphysicsjumpanimated-texture

2D (With Planes) Jump Script

I am working on a 2D platformer-type game. To achieve proper 2D, I have been using planes for characters, and then a slightly modified version of THIS script. I have got basic movement working with transform.Translate() , but I just can't achieve jumping!

This is my script for my player:

var uvAnimationTileX = 24;

 var uvAnimationTileY = 1;                      

var framesPerSecond = 10.0;

var jumpSpeed : float = 10;

var textures : Texture2D[];

/* textures:

 1 = running right

 2 = idle

 3 = running left

*/

function Start() {

}

function Update () {

 if(Input.GetKey(KeyCode.RightArrow))

 {

     ChangeAnimation(0, 3, 10);

     transform.Translate(Vector3.left * 4);

 }

 else if(Input.GetKey(KeyCode.LeftArrow))

 {

     ChangeAnimation(2, 3, 10);

     transform.Translate(Vector3.right * 4);

 }



 else

 {

     ChangeAnimation(1, 4, 7);

 }



 if(Input.GetKeyDown(KeyCode.Space))

 {   

     Jump();

 }



 if(Input.GetKeyDown(KeyCode.LeftControl))

 {



 }


}

function ChangeAnimation(arrayIndex : int, frames : int, fps : int)

 {

     uvAnimationTileX = frames;

     // Calculate index

     framesPerSecond = fps;

     var index : int = Time.time * framesPerSecond;

     // repeat when exhausting all frames



         index = index % (uvAnimationTileX * uvAnimationTileY);



     // Size of every tile

     var size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);



     // split into horizontal and vertical index

      var uIndex = index % uvAnimationTileX;

     var vIndex = index / uvAnimationTileX;



     // build offset

     // y coordinate is the bottom of the image in opengl so we need to invert.

     var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);



     renderer.material.SetTexture("_MainTex", textures[arrayIndex]);



     renderer.material.SetTextureOffset ("_MainTex", offset);

     renderer.material.SetTextureScale ("_MainTex", size);

 }





function Jump()

{

}

But what would go into that Jump() function?

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 FLASHDENMARK · Apr 01, 2011 at 04:17 PM 0
Share

Are you using a Rigidbody or CharacterController?

avatar image Xedfire 1 · Apr 01, 2011 at 05:03 PM 0
Share

Neither, as the player only moves along the x axis. Would I need one to use the y axis properly? Or could I get away with using another transform.Translate() in some way?

0 Replies

· Add your reply
  • Sort: 

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

How to animate collider along with object for 2D game? 1 Answer

2D Ragdoll 1 Answer

2d grounded check problem? 3 Answers

Incremental jump while pressing Jump button 0 Answers

Help with 2D Hit Detection! 0 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