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 voinekku · Sep 22, 2014 at 09:14 AM · jumpplatformerlinecastgrounded

2,5D game jump script with multiple linecasts to check if grounded

Hello there!

First I have to apologize for a very noob question I should've found answer to myself. I've been playing around with unity for merely few weeks and trying to learn scripting from the tutorials and examples. I completely do understand that instead of asking somebody to help out, it would be much more beneficial for myself to find the answer through learning the basics better.

However, after experimenting multiple options and being stuck for a week now, I've decided to ask here in case some kind sould wouldn't mind helping me out. What I'm trying to create is an 2,5d platformer game. I find it absolutely necessary to have multiple linecasts to make jumping reliable even on a uneven ground. However I'm finding horrible problems trying to figure out how to make it work. I've went through the example script from the Unity Projects 2D Platformer by Unity Technologies and the script provided by Invertex in this thread: http://forum.unity3d.com/threads/how-to-deal-with-characters-at-the-corners-of-platforms.223204/. However my multiple attempts trying to combine them in many different ways have failed miserably.

This is what I've come up with this far:

private Transform groundCheck1Center;
private Transform groundCheck1Left;
private Transform groundCheck1Right;
private bool groundedC=false;
private bool groundedL=false;
private bool groundedR=false;
private bool grounded = false;
void Awake()
{
        groundCheck1Center = transform.Find("groundCheck1Center");
        groundCheck1Left = transform.Find("groundCheck1Left");
        groundCheck1Right = transform.Find("groundCheck1Right");
}
    void Update()
    {
        groundedC = Physics.Linecast(transform.position, groundCheck1Center.position);
        groundedL = Physics.Linecast(transform.position, groundCheck1Left.position);
        groundedR = Physics.Linecast(transform.position, groundCheck1Right.position);
        if((groundedC = true) ||(groundedL = true) || (groundedR = true))
        {
            grounded = true;
            Debug.Log ("grounded");
        }
        else
        {
                   grounded = false;
            Debug.Log ("not grounded");
        }
        if(Input.GetKeyDown(KeyCode.UpArrow) && grounded)
            jump = true;
    }

The problem seems to be that the script returns grounded as true from the very start of the game and never changes it's value. I did manage to get the single linecast version to work using the 2D Platformer script, so the problem shouldn't lie in finding the groundCheck - objects.

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 Graham-Dunnett · Sep 22, 2014 at 09:16 AM

Look up the difference between the assignment operator (`=`) and the equals operator (`==`).

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 dmg0600 · Sep 22, 2014 at 09:46 AM 0
Share

Extra hint: Wrong operators in if((groundedC = true) ||(groundedL = true) || (groundedR = true))

avatar image voinekku · Sep 22, 2014 at 10:28 AM 0
Share

Thank you, I can't believe the problem was so simple!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

issues with jumping and linecast2d and raycast2d 0 Answers

Unable to check if grounded 1 Answer

i'dont want double Jump 1 Answer

I'm making a 2D mobile platformer and I just figured out how to make the mobile buttons work. But I can't get the jump limit to work. Does anyone know how to create maybe a ground detection with this script? 1 Answer

Grounded bool acting weird 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