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 CraftyMaelyss · Sep 10, 2016 at 01:17 PM · c#follow player

How do I stop small animated models from falling to the ground?

Basically I've made some butterflies for my game with an animator that makes them flutter around in the air and head towards the player, except instead of flying towards the player, they basically face-plant into the ground and hop over towards the player.

While this is hilarious, I just want to have it so the butterflies fly towards my player, here's the script I'm using in case anyone knows how to modify it so they stay in the air:

 // Use this for initialization
 void Start () {

 }
 //The target player
 public Transform Basehuman01b;
 //At what distance will the enemy walk towards the player?
 public float walkingDistance = 10.0f;
 //In what time will the enemy complete the journey between its position and the players position
 public float smoothTime = 10.0f;
 //Vector3 used to store the velocity of the enemy
 private Vector3 smoothVelocity = Vector3.zero;
 //Call every frame
 void Update()
 {
     //Look at the player
     transform.LookAt(Basehuman01b);
     //Calculate distance between player
     float distance = Vector3.Distance(transform.position, Basehuman01b.position);
     //If the distance is smaller than the walkingDistance
     if(distance < walkingDistance)
     {
         //Move the enemy towards the player with smoothdamp
         transform.position = Vector3.SmoothDamp(transform.position, Basehuman01b.position, ref smoothVelocity, smoothTime);
     }
 }

Again any advice is greatly appreciated :)

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 Bigiansen · Sep 10, 2016 at 02:06 PM 0
Share

Sounds like you have a rigidbody attached to each butterfly. Check the components of the butterflies for a rigidbody and disable gravity for it.

avatar image CraftyMaelyss Bigiansen · Sep 10, 2016 at 02:10 PM 0
Share

I looked at the inspector and couldn't find anything like that: alt text

alt text

buttersplat2.png (115.2 kB)

1 Reply

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

Answer by Bigiansen · Sep 10, 2016 at 02:23 PM

I've tested your script and it seems to work

Have you checked if the pivot point of the player is not below the ground?

Comment
Add comment · Show 4 · 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 CraftyMaelyss · Sep 11, 2016 at 01:03 AM 0
Share

I don't think so, the butterfly model is above the mesh I made for the environment, unless you mean that white grid is the default ground?

This is what the model looks like when the game isn't running if that helps: alt text

buttersplat3.png (472.6 kB)
avatar image Bigiansen · Sep 11, 2016 at 03:17 PM 0
Share

I mean the pivot point of the player. Your butterfly is targeting the pivot point of the player (transform.position), so if the pivot point of the player is below the ground, the butterfly will just fly downwards.

avatar image Bigiansen · Sep 11, 2016 at 03:18 PM 1
Share

Try something like this:

transform.position = Vector3.SmoothDamp(transform.position, Basehuman01b.position + new Vector3(0,2,0), ref smoothVelocity, smoothTime);

That + new Vector3(0,2,0) is a vertical offset for the target position. Try increasing/decreasing the Y value.

avatar image CraftyMaelyss Bigiansen · Sep 12, 2016 at 02:30 AM 0
Share

That worked, thank you so much! :D The only issue I'm having now is trying to line up the glowing effect with the butterfly but I should be able to fix that be re-positioning the light P: alt text

buttersplat4.png (191.8 kB)

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

233 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Mega Man Style Camera Movement 0 Answers

The name `followerPosition' does not exist in the current context 1 Answer

How to make an npc/ai walk next to the player? (C#) 1 Answer

Enemy Follow Player tutorial? 1 Answer

Making an object follow another object C# 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