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 /
This question was closed Nov 10, 2014 at 08:53 PM by robertbu for the following reason:

Duplicate Question

avatar image
0
Question by OctoSloths · Nov 10, 2014 at 08:53 PM · c#

2D character controller script not working?

Hey, I'm trying to make a 2D character controller, I'm running into a lot of errors, does anyone see what the issue is?

 using UnityEngine;
 using System.Collections;
 
 
 public class RobotControllerScript : MonoBehaviour
 {
     public float maxSpeed = 10f;
     bool facingRight = true;
 
     Animator anim;
 
     bool grounded = false;
     public Transform groundCheck;
     float groundRadius = 0.2f;
     public LayerMask whatIsGround;
     public float jumpForce = 700f;
 
     bool doubleJump = false;
 
     void Start ()
     {
         anim = GetComponent<Animator> ();
     }
     void FixedUpdate ()
     {
         grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);
         anim.SetBool ("Ground", grounded);
 
         if (grounded)
             doubleJump = false;
         anim.SetFloat ("vSpeed", Rigidbody2D.velocity.y);
 
         if(!grounded) return;
 
         float move = Input.GetAxis ("Horizontal");
 
         anim.SetFloat ("Speed", Mathf.Abs (move));
         Rigidbody2D.velocity = new Vector2(move + maxSpeed, Rigidbody2D.velocity.y);
 
         if (move > 0 && !facingRight)
             Filp ();
         else if (move < 0 && facingRight)
             Filp ();
     }
     void Update ()
     {
         if ((grounded || !doubleJump) && Input.GetKeyDown (KeyCode.Space)) 
         {
             anim.SetBool("Ground", false);
             Rigidbody2D.AddForce(new Vector2(0, jumpForce));
             if(!doubleJump && !grounded)
                 doubleJump = true;
         }
     }
     void Flip()
     {
         facingRight = !facingRight;
         Vector3 theScale = Transform.localScale;
         theScale.x *= -1;
         Transform.localScale = theScale;
     }
 }

Comment
Add comment · Show 1
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 AlwaysSunny · Nov 10, 2014 at 08:03 PM 0
Share

This question isn't descriptive enough. In what way does it not work as expected? Please give us a clue when asking questions here.

1 Reply

  • Sort: 
avatar image
0

Answer by robertbu · Nov 10, 2014 at 08:55 PM

For future questions, please include copies of your error messages.

References to your Rigidbody component should use 'rigidbody' with a lower case 'r'. I see this problem on lines 31, 38 and 50.

References to your Transform, should use 'transform' with a lower case 't'. I see this problem on lines 58 and 60.

You've misspelled 'Flip()'.

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

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Problem with dictionary inside of a class 0 Answers

Separating mouse button clicks from GUI and game input 1 Answer

How to get this object to move 2 Answers

how to change Texture Max Size with scripting 1 Answer

How to find all GameObjects in a parent in shorter code than I figured out 1 Answer


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