Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ytwithlove · Jul 25, 2018 at 03:46 AM · rigidbody2daddforce movement

Rigidbody2D Warning and Error messages

I'm working from the book Unity 5.x Game Development Blueprints and I'm on the Mobile Endless Game (aka Flappy Bird clone). I'm receiving a Warning message and an Error message in Unity about my Rigidbody2D object. Not really sure what's going on since the code I'm using seems to be correct according to the other posts I've found. I'm also having trouble with getting the .AddForce() to work - this is probably because the Rigidbody2D isn't working.

Here's the messages I'm getting: alt text

Here's my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 //[RequireComponent (typeof(Rigidbody2D))]
 public class PlayerBehavior : MonoBehaviour {
 
     [Tooltip("The force which is added when the player jumps")]
     public Vector2 jumpForce = new Vector2(0, 300);
 
     // If we've been hit, we can no longer jump
     private bool beenHit;
     private Rigidbody rigidbody2D;
 
 
     // Use this for initialization
     void Start () {
 
         beenHit = false;
         rigidbody2D = GetComponent<Rigidbody2D> ();
     
     }
 
     // Will ne called after all of the Update functions
     void LastUpdate () {
 
         // Check if we should jump as long as we haven't been hit yet
         //if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) && !beenHit) {
         if (Input.GetKeyDown(KeyCode.Space)) {
 
             Debug.Log ("jump!");
 
             // Reset velocity and then jump
             rigidbody2D.velocity = Vector2.zero;
             rigidbody2D.AddForce (jumpForce);
 
         }
     }
 
     // If we collide with any ofthe polygon colliders then we crash
     // other: what we collided with
     void OnCollisionEnter2D (Collision2D other) {
 
         // We have now been hit
         beenHit = true;
 
         // The animation should no longer play, so we can set the speed to 0 or destroy it
         GetComponent<Animator>().speed = 0.0f;
 
     }
 }
 

rigidbody2d-error.png (326.2 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by haidao0923 · Jul 25, 2018 at 04:08 AM

line 13 private Rigidbody2D rigidbody2D

you were trying to Get a Rigidbody2D component and place it into a container suitable for only the regular Rigidbody

Comment
Add comment · Show 1 · 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 ytwithlove · Jul 26, 2018 at 12:07 AM 0
Share

@haidao0923 Awesome! That took care of the Rigidbody error. I'm still having trouble with the AddForce(). I'm thinking it has something to do with all the checks that are happening with the spacebar and the mouse clicks.

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

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

Related Questions

Rigidbody 2d smooth movement problem (It's jerky) 1 Answer

Rigidbody2d.AddForce behaving odd 1 Answer

How to stop input after hitting a certain velocity 1 Answer

Move character with AddForce 2 Answers

Disabling script while in certain position 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