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 Dachckol · Aug 16, 2012 at 07:46 PM · physicsrigidbodyfpsenemy

How to stop an rigidbody enemy from jumping when chasing the player?

Hello, I am developing a simple fps game where the player is on a map with some hills and a forrest. Enemies spawn round the edges of the map and walk towards the player. The player has to shot them 5 times to kill before they reach him. The player can move, I used a First Person Controller.

The problem I am facing is that the enemies start to jump around and glich when they are waling towards the player. There is no errors in the console when the game is running. This is the code used for the enemies:

 #pragma strict
 
 var player:Transform;
 var speed:float;
 
 function Start()
 {
     player = GameObject.Find("First Person Controller").gameObject.transform;
 }
 
 function Update () {
     transform.LookAt(Vector3(player.position.x , 0.0 ,player.position.z));
     transform.position += Vector3(transform.forward.x,0,transform.forward.z)*speed*Time.deltaTime;
 }

For the enemies I used a model made in wings3D. The model is in a shape of a zombie with its arms stretched out in front of it. I have set colliders to each part of the model (box colliders) and made the whole thing rigidbody. As you can see in the code there is nothing in the code that would make the enemy jump and glich out. The code worked without any problem when the enemy was only a cube. This makes me think that it is the physics of the model that are causing the problem.

How do I stop the enemy to jump and glich when approaching the player?

Thank You, Dachckol

Comment
Add comment · Show 2
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 flaviusxvii · Aug 16, 2012 at 10:16 PM 0
Share

"Jump" in what sense? Up in the air? Or do they teleport ahead faster than they should?

avatar image Dachckol · Aug 17, 2012 at 08:39 AM 0
Share

They jump up in the air, in some cases they continue flying forever and in some they fall.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by nikescar · Aug 16, 2012 at 11:01 PM

You are correct. It is the physics that is causing the problem. You said that you attached rigidbodies to the zombie game objects. When you do this the physics system starts to control their position. The problem comes in when you override the physics by using transform.position. Then the physics engine has to catch up to the new position and it's all, "What kind of sorcery is this?"

To move a physics object you should use something like AddForce.

I haven't mess with character movement before but something like...


var speedModifier : float = 10;
rigidbody.AddForce((player.position-transform.position) * speedModifier);
...may be a good place to start.
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 Dachckol · Aug 17, 2012 at 09:51 AM 0
Share

Thank You for the reply. I have used the code you provided but I added a *Time.Delta time after multiplying the direction by the speed.

After configuring the mass and the speed of the enemy everything started working.

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

10 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

Related Questions

Multiple Cars not working 1 Answer

Best way for rigidbody enemy? 1 Answer

How do you add a fixed joint to a first person controller 1 Answer

Projectile Boomerang 1 Answer

RigidBody.MovePosition seems jerky in movement 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