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 Zexstoi · Dec 29, 2017 at 11:44 AM · unity 5rigidbodyenemyfollow playervibration

Enemy Rigidbody vibration when reaching the player

Hello programmers around the world I am having a problem with one of my scripts for the enemy in my game. It is supposed to follow the player to a certain beyond which it actually reaches the player However, when it goes beyond that point it just vibrates around back and forth as if it is colliding with the player. However that is not the case because I change the point from 1.2f from the player to 10.2 and the result was the same as if the player is hitting an invisible wall. Side node: I am not trying to collide with any box or capsule or character colliders so the issue is not there. I am trying to figure how to solve this problem and I've been at it for a month now with rigidbodys, LateUdate(), FixedUpdate() and AddForce so nothing seems to work. At this point any help would be appreciated. Here is my code for following the player:

public float MyAttackRange { get; set; } private Vector3 direction; [SerializeField] private EnemyScript enemy; [SerializeField] private Player player; private Transform target; public float autoAttackCoolDown; public float autoAttackCurrentTime; void Start() { MyAttackRange = 1.2f; } private void FollowTarget() { if(target != null && player.inLineOfSight) { StopCoroutine(EnemyIdle()); float distance = Vector3.Distance(player.transform.position, enemy.transform.position); if(distance > enemy.MyAttackRange) { Vector3 targetDir = player.transform.position - transform.position; float step = runSpeed * Time.deltaTime; Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0F); transform.rotation = Quaternion.LookRotation(newDir); direction = (target.transform.position - transform.position).normalized; transform.position = Vector3.MoveTowards(transform.position, target.position, runSpeed * Time.deltaTime); if(distance == enemy.MyAttackRange) { eAnim.SetBool("walk", false); rBody.velocity = Vector3.zero; direction = Vector3.zero; } } if(distance <= enemy.MyAttackRange) { if(player != null) { if(autoAttackCurrentTime < autoAttackCoolDown) { autoAttackCurrentTime += Time.deltaTime; } else { DoDamage(15); player.GetComponent<Player>().health.CurrnetValue -= 15; autoAttackCurrentTime = 0; } } } } else { direction = Vector3.zero; } }

I'm out of options. Any help would be appreciated at this point. Thanks in advance! Remember the goal is for the enemy to stop shaking and vibrating back and forth when he reaches the 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

0 Replies

· Add your reply
  • Sort: 

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

160 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

Related Questions

Enemy vibrates when it reaches the player 0 Answers

Unity3D : Enemies following the player keep moving through each other 1 Answer

Help with Generating level 0 Answers

My healtbar is not change when i look another enemy 0 Answers

How does instantiate connect to rigidbody?,How does instantiate userigidbody without getcomponent? 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