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 /
This question was closed Jan 05, 2021 at 02:43 PM by MustiKe for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by MustiKe · May 31, 2020 at 10:29 AM · rigidbody2denemy aifollow player

Enemy Follow Player Without Rigidbody2D

Hello guys I just want to know is there a way to make enemy follow player without using rigidbody2D? Because my enemies just getting glitched when they collide with my player

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

2 Replies

  • Sort: 
avatar image
0

Answer by WaqasHaiderDev · May 31, 2020 at 10:50 AM

Hi, you can use any of the following

 transform.position = Vector3.MoveTowards(transform.position, target.transform.position, speed * Time.deltaTime);

or

 transform.position = Vector3.Lerp(transform.position, target.transform.position, Time.deltaTime * speed);

But remember that in MoveTowards, your object will follow target at constant speed but in case of Lerp, your object will be fast at start but as the distance will reduce, it will start to decrease speed and will show ease in effect. Check how Lerp works otherwise tell me and I will explain to you.

Comment
Add comment · Show 5 · 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 MustiKe · May 31, 2020 at 11:44 AM 0
Share

I was using the first one so it didn't change anything and I don't want to use lerp.I am working on tower defense game that enemies come to you and you shoot with rigidbody attached bullets but my problem is when I shoot using bullet, bullet boosts them and enemies stop moving, and If I don't use rigidbody on enemies they overlap

avatar image WaqasHaiderDev MustiKe · May 31, 2020 at 11:58 AM 0
Share

I did not get this at all.

"but my problem is when I shoot using bullet, bullet boosts them and enemies stop moving"

what do you mean by boosting? Also movement should not stop as $$anonymous$$ove.towards will keep on moving TRANSFOR$$anonymous$$ towards the target. Share some gif or image if possible. Also share some more code.

avatar image MustiKe WaqasHaiderDev · May 31, 2020 at 12:51 PM 0
Share

here is the video link: https://youtu.be/$$anonymous$$ATTJCn05w0 if I dont use rigidbody on bullet It doesnt do any damage If I dont use rigidbody on enemies they just overlap

avatar image thealexguy1 MustiKe · May 31, 2020 at 12:22 PM 1
Share

$$anonymous$$ake the bullet's mass really really low, and adjust the speed accordingly. Then depending on what you want the easy option is to just set the enemies velocity to be constant every frame rather than AddForce.

avatar image MustiKe thealexguy1 · May 31, 2020 at 12:57 PM 0
Share

I just make the bullet's mass very low and it's worked thank you!

avatar image
0

Answer by tadadosi · May 31, 2020 at 01:12 PM

You can achieve what you want without adding a rigidbody to your enemies:


  1. Add a collider and a rigidbody to your bullet (marked as kinematic) .

  2. Add a collider to your enemy marked as IsTrigger and create a new tag for your enemy which can be called Enemy.

  3. Add logic to your bullet code to get the trigger collision.


Here is how the trigger collision code should look like in your bullet:

    private void OnTriggerEnter2D(Collider2D collision)
     {
         if (collision != null)
             if (collision.CompareTag("Enemy"))
             {              
                 // Play sound or any other stuff
                 // You could find your enemy script like this 
                 // Enemy enemy = collision.GetComponent<Enemy>();
                 // and do something with it like enemy.AddDamage(bulletDamage);
             }
     }


With this method there are no forces involved in the process, just the function to get the collision.

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

132 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

Related Questions

Making enemy follow character on uneven terrain 1 Answer

If anyone here has used the Playground Project to make a game before, how would I have an enemy follow the player while still having gravity apply to said enemy? 0 Answers

My enemy is not moving properly on a terrain 0 Answers

Complex Enemy follow AI 1 Answer

How would I move enemies at an angle towards the player, instead of just moving them straight? 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