• 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 Sep 01, 2017 at 06:24 PM by Geads for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Geads · Aug 29, 2017 at 12:09 AM · 2djumpingplatformerplatformenemy ai

2D Sidescroller enemy AI jump help! Picture Included!

alt text

Hello everyone. I'm learning Unity and this is my very first project.

I have a 2d side scroller with a player and an enemy AI.

The enemy AI targets the player and can follow the player and flip directions as needed.

my question is how can I get this AI to jump to the platform the player does in order to continue following the player?

I've read things about waypoints, navmesh, triggers, ect ect. The problem is I don't know what they all can do and like I said I'm very new so a tutorial would be amazing!

unity2d-help.png (202.8 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

3 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Geads · Aug 31, 2017 at 04:45 PM

How would you link both box colliders? I understand if the AI enters the first one then jump, but how would you script if ai is in bottom 2dcollider and player is in top 2dcollider then jump?

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 PersianKiller · Aug 31, 2017 at 04:57 PM 0
Share

in your player code create a bool that if player is in up boxCollider2D then make the bool true. then in your enemy code create another bool when he's in down collider2D then the bool true.

then in your enemy code use something like this

    public playerController player;   // object that has your player codes
   void Awake () {
 
     player = FindObjectOfType<playerController> (); // so you can access to script of  the object that has playerController script.


}

              void Update(){
          if (player.IsinTheUpCollder2D && enemyIsIntheGroundCollider2D) {

// IsinTheUpCollder2D it's box collider that is on the upper Ground //enemyIsIntheGroundCollider2D it's box collider that is on the Ground

                                    jump;
     }


}

hope you get the idea

avatar image
0

Answer by PersianKiller · Aug 29, 2017 at 06:25 PM

dude I give you an easy solution :). place a box collider 2d on the ground. then if enemy is in the boxcollider that is on the ground and the player is in the boxcollider that is top of the ground,then enemy shold jump :).you can use OnTriggerEnter2D function and it's very easy .hope it gives you some ideas :D alt text


100842-unity2d-help.png (234.7 kB)
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
avatar image
0

Answer by Duvic · Aug 31, 2017 at 05:33 PM

Its a fine idea to do 2dTriggers and its not wrong but i would use a ray cast. it's not that compleceted to lern and it is so importent for unity i use it in one way or anather in evre game i make. you culd chack the distance with the ray and tell him to jump at a certain point, this way you dont need to manually position every jump point.

heres the link for 2d ray casting: https://docs.unity3d.com/ScriptReference/Physics2D.Raycast.html

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 PersianKiller · Aug 31, 2017 at 05:48 PM 0
Share

hehehe, yes ,I heard that we should use raycast , but I prefer to do my works with simplest way :)

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

127 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 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

Spawning animals at a random postion on platforms. 2 Answers

I'm trying to make platforms generate between two platforms which are already generated. 0 Answers

Problem of gravity 1 Answer

I have a problem with my enemy AI script 1 Answer

How to jump in 2D? 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