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 Subhi · May 28, 2011 at 09:01 AM · fly

how to make a Ghost and a fly script

Hi. i have a character and i want to make him fly and i want him to have a ghost ability (he can walk throw walls)

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
1
Best Answer

Answer by nhftk12 · May 28, 2011 at 09:58 AM

This is the flying code:

 var targetDistance;
  var target : Transform;
  var moveSpeed = 8.0;
  var damping = 3.0;
  
  function Update ()
  {
      targetDistance = Vector3.Distance(target.position, transform.position);
      
      var rotation = Quaternion.LookRotation(target.position - transform.position);
      transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
      
      var offsetDirection = target.position - transform.position;
      offsetDirection.y = 0;
      var rotation2 = Quaternion.LookRotation(offsetDirection);
      transform.rotation = Quaternion.Slerp(transform.rotation2, rotation, Time.deltaTime * damping);
      transform.Translate(offsetDirection.normalized * moveSpeed *Time.deltaTime, Space.World);
  }

Attack this to the ghost, it will follow you allways at the same height.

For the ability of going through wall: just don't put any colliders on the ghost. If you want it to collide with something: put all the collders on "Trigger".

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 nhftk12 · May 28, 2011 at 10:07 AM 1
Share

If you want it not to look at you but still look to your dirction (disable rotation on the x and z axis) $$anonymous$$ETE this line: "var rotation = Quaternion.LookRotation(target.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);

"

avatar image Subhi · May 28, 2011 at 10:53 AM 0
Share

thankz i will test it

avatar image Subhi · May 28, 2011 at 01:01 PM 0
Share

how can i make the character moves right and left while fling

avatar image nhftk12 · May 28, 2011 at 01:37 PM 1
Share

If you want the ghost will stay on the same height and go to the side add this line to the end of the code "transform.Translate(Vector3.right moveSpeed Time.deltaTime);" (in this line it will go to the right, you can change the sides by write "left" or "right"), BUT the ghost will go to the side AND forward, it will seems like the ghost is tring to pass you from your side. If you want the ghost will really go to the side so delete the last 5 lines in the code and add the line I gave you now, there is a problem with that because I didn't really tried the code by going to the sides so I don't sure the ghost will keep to go on the same height... (It not me who made that code...)

avatar image Subhi · May 28, 2011 at 02:23 PM 0
Share

thanks very much the code is completely ok but the ghost walks throw the sides i don't want the ghost to walk throw any thing

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

2 People are following this question.

avatar image avatar image

Related Questions

Problems entering in Fly Mode 1 Answer

ObjectSpawner 1 Answer

Move Object a direction with one button and move the object back with the same button? 1 Answer

Another question about the flying enemy 1 Answer

Identifying a particular script 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