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 /
  • Help Room /
avatar image
0
Question by Zerro123321 · Apr 20, 2020 at 03:59 PM · 2d-platformer

How can i make an AI jump in UNITY 2D Platform Game,Unity 2 AI chase Jumping

Hello guys. I am new to this think with Unity and have 0 skills in scripting. It will be much of a help if you manage to answer my question.

I build i game where i have 2 characters: Player and Enemy. I used Astar Pathfinder to make the Enemy chase the player around the level. However the Enemy should be grounded object that has to walk and jump over platforms i build . Once the Enemy hit shoot or catch the player the game should end. Anyways, the Enemy initially is chasing the player and everything looks fine, but when it comes to jumping on the platform i can not figure out how to do it and where to find an answer for this. Could please help me with this. I want make the Enemy to jump on platform while it chases the Player. I would appreciate any help i could get resolving this problem i have. Thank you very much

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

Answer by SilverFang180882 · Aug 05, 2020 at 02:04 PM

Stumbled across this while looking for a solution to make my AI double jump (my coroutine waits for him to land before doing the second jump).

Anyway, here's what I have to make an AI enemy jump (assuming you already have him moving left or right, based on which side the player is in relation to him);

 GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpHeight);

"jumpHeight" is a float value you'd create yourself. Whatever value you set it to will depend based on how high you want your character to jump.

Hope that helps!

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 Goldenhay · Nov 20, 2020 at 10:58 AM 0
Share

Where would I put the code you have provided? I am extremely new to Unity and writing code for it and wondered if this goes in the void update, void start, or somewhere else, and creating the float value is just outside on it's own correct? sorry if this is a lot of questions like I said I am very new to this but still want to make an enemy that jumps

avatar image SilverFang180882 Goldenhay · Nov 20, 2020 at 08:00 PM 0
Share

I'm not sure what your code looks like, but do you have something which enables the enemy to detect the platform? And what he should do when he/she comes into contact with one? If you did, you'd put that jump code in there. Pretty much his/her "action" when he detects the platform you want him/her to jump on.

EDIT: I just realised you aren't the original poster (unless you're using two accounts). It's usually in Update, but Update runs continuously, so if you put it in there just like that, the enemy would just jump continuously, effectively flying off into the sky. You'd need to put it within whatever condition which you want to trigger the enemy's jump.

For example, if you want the enemy the jump at the exact same time as the player, it'd be something like this:

 if (thePlayer.grounded == false)
 {
 GetComponent().velocity = new Vector2(GetComponent().velocity.x, jumpHeight);
 }

This would go in Update, so the enemy will jump every time the player does. I personally like to create a separate function for the jump itself (or a coroutine, if I want to delay it).

If you're very new with code, I'd highly suggest finding a unity tutorial series and following through it. Will really help you learn with games coding.

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

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

Player bounce when not supposed to 1 Answer

Why doesn't this script work? 1 Answer

how to make "gravity areas"? 0 Answers

Interactive tutorial 2d platformer not working 1 Answer

Jump then crouch attack performing when you crouch then jump (Unity2D) 0 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