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 TheBlackBox · Feb 20, 2014 at 05:40 PM · 2d

I have 3 Questions I Need Answering, Can You Help?

Ok, so i have been asking alot of questions recently so i am sorry. Basically i just had this script fixed

 #pragma strict
 var moveSpeed : float = 8;
 var jumpSpeed : float = 25;
 var fallSpeed : float = 64;
 var maxFallSpeed : float = 60;
 var maxUpSpeed : float = 25;
 var slopeLimit : float = 45;
 var dashSpeed : float = 120;
 var fly : boolean;
  
 private var vm : float;
 var onGround : boolean;
 private var xScale : float;
 private var h : float;
 private var v : float;
 private var jump : boolean;
 private var anim : Animator;
 private var boxcoll : BoxCollider2D; //If boxCollider2D is used replace w/ ... private var boxColl : BoxCollider2D;
  
 function Start () {
         xScale = transform.localScale.x; //Get correct starting Orientation for player.
         anim = gameObject.GetComponent("Animator"); //Get Animations for character
         boxcoll = GetComponent(BoxCollider2D); //if boxCollider2D is used replace w/... boxColl = GetComponent(BoxCollider2D);
 }
  
 function Update () {
         h = Input.GetAxisRaw("Horizontal"); //get horizontal input
         v = Input.GetAxisRaw("Vertical"); //get vertical input
         jump = Input.GetKey(KeyCode.Space); //get jump input
 }
  
 function FixedUpdate(){
         if(onGround && jump){ //Are we grounded can we jump?
                 vm = jumpSpeed;
         }
        
         var moveH : float = h * moveSpeed * Time.deltaTime; //Smooth horizontal movement
         //Flip character orientation
         if(h < 0){
                 transform.localScale.x = -xScale;
         } else if(h > 0){
                 transform.localScale.x = xScale;
         }
        
         anim.SetFloat("VM", vm); //Animate VM parameter
         anim.SetBool("Grounded", onGround); //Animate Grounded parameter
         rigidbody2D.AddForce(Vector2.right * moveH); //Apply horizontal movement
         rigidbody2D.AddForce(Vector2.up * vm); //Apply vertical movement
        
         if(fly){ //Can we fly?
                 if(v > 0){
                         //Fly like a bird!!!
                         vm += v * Time.deltaTime * 20;
                 } else {
                         //Uh oh it's gravity
                         vm -= fallSpeed * Time.deltaTime;
                 }
         } else {
                 //Gravity ... ouch!
                 vm -= fallSpeed * Time.deltaTime;
         }
        
         vm = Mathf.Clamp(vm, -maxFallSpeed, maxUpSpeed); //Clamp vertical speeds
         rigidbody2D.velocity = Vector2.zero; //Stop movement if there is no input
         onGround = false; //Clear out grounding check
 }
  
 function OnCollisionEnter2D(c : Collision2D){
         CheckCollision(c);
 }
  
 function OnCollisionStay2D(c : Collision2D){
         CheckCollision(c);
 }
  
 function CheckCollision(c : Collision2D){
         for(var contact in c.contacts){
                 //Check for floor hit
                 //If boxCollider2D is used replace circCollider.radius w/ (boxCollider2D.size.y/2)
                 if(vm <= 0 && contact.point.y <= transform.position.y - (boxcoll.size.y/2) && Vector2.Angle(Vector2.up, contact.normal) <= slopeLimit){
                         onGround = true;
                         vm = Mathf.Max(0, vm);
                 }
         }
  }

Ok, the code no longer has errors but it doesn't run how i want it too and i'm not sure how i can adapt it. Currently the script helps my player move left, right and jump, it also displays the correct animation but the animation never stops. I would like the animation to stop and stay at a single frame when the character is still and i'm not sure how i can do this?

Also since the code is working when i play the game it runs at 3 fps, this is a problem because the game just looks bad and doesn't really work very well...

Finally, the animation will not switch before it is finished so if i was moving left the animation would play and it would take around 3 seconds to finish, i cannot change direction until this animation is finished and i don't know how i can stop this.

I'm sorry that i am such a noob but i am really struggling to get the hand of this... It is also worth noting that this is a 2D game running with all of the 2D defaults.

Thankyou and if you need anything please just ask and i will give you what you need.

Comment
Add comment · Show 8
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 TheBlackBox · Feb 20, 2014 at 06:39 PM 0
Share

Does anybody know?

avatar image TheBlackBox · Feb 20, 2014 at 06:43 PM 0
Share

Anybody?

avatar image TheBlackBox · Feb 20, 2014 at 07:35 PM 0
Share

Can anybody seriously help me?

avatar image Stormizin · Feb 20, 2014 at 07:41 PM 0
Share

It's a character animation? Try to use the animator tool.

avatar image TheBlackBox · Feb 20, 2014 at 07:47 PM 0
Share

Yes i know this, i have tried my best with the animator tool but i don;t fully understand how it works. I already have the animation set up i just need it to 1. play faster 2. not be active when i'm not moving and 3. Stop mid animation to start a different animation...

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by POLYGAMe · Feb 20, 2014 at 08:20 PM

The speed issue is likely to be draw calls or something like that. How many tris in your scene? How many different materials? As for the animation starting and stopping, that really is the most basic of scripting. Use bools. Game designing isn't something you can just pick up on the fly. I suggest learning basic JS or C# via the many online tutorials before you even think about making a game. There are lots of decent tutorial videos on the Unity site now too. Without understanding the basics, you'll get nowhere.

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

20 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

Related Questions

Multiple Cars not working 1 Answer

JS to C# Translation? 2 Answers

How do I get character to always face mouse? 2 Answers

Win game based on destroying enemys 2 Answers

Convert js to c# 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