Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Ian9921 · Jun 03, 2016 at 06:15 AM · javascriptspawnglitchflightdistance check

Glitching through ceiling when spawning blocks under the player

In a magic based game I am using a somewhat unconventional flight script that works through spawning invisible cubes under the player and destroying them soon after. The only problem with this is that it causes the player to glitch through the ceiling of the chamber. In what ways can this be avoided? I was thinking of finding a way to test distance to the ceiling, but I am unfamiliar with how to do this. I am also open to other suggestions.

Comment
Add comment · Show 1
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 ninja_gear · Jun 03, 2016 at 09:02 PM 0
Share

It might be a little easier to just learn how to work with a CharacterController. Instantiating things like that can be costly.

1 Reply

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

Answer by Wolfrik_Creations · Jun 03, 2016 at 06:31 AM

Here you go.

 var distToRoof : float;
 
 function Update(){
     var temp : RaycastHit;
     Physics.Raycast(transform.position, Vector3.up, temp);
     distToRoof = Vector3.Distance(temp.point, transform.position).y;
 }
Comment
Add comment · Show 6 · 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 Ian9921 · Jun 03, 2016 at 07:17 PM 0
Share

@Wolfrik_Creations When I use this code, I get an error saying "'y' is not a member of 'float'" how can I fix this?

avatar image Wolfrik_Creations Ian9921 · Jun 03, 2016 at 07:43 PM 0
Share

Oh sorry, I thought Vector3.Distance returned a Vector3.

At the end of line 6 remove ".y".

It should be this

 distToRoof = Vector3.Distance(temp.point, transform.position);

avatar image Ian9921 Wolfrik_Creations · Jun 03, 2016 at 08:19 PM 0
Share

Unfortunately, that doesn't work. the player will still glitch through the ceiling. $$anonymous$$y current code looks like this:

 var distToRoof : float;
 var flying = false;
 
 function Update ()
 {
         var temp : RaycastHit;
     Physics.Raycast(transform.position, Vector3.up, temp);
 
     distToRoof = Vector3.Distance(temp.point, transform.position);
 
         if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.Space))
     {
         if (flying == true)
         {
             if (distToRoof < .28)
             {
                 Debug.Log ("Flight Attempted");
                 flightTimer ++;
                 var fly = Instantiate(flightPrefab, transform.position, transform.rotation);
                 Destroy(fly.gameObject, 2);
                 Debug.Log ("Flight Successful");
             }
         }    
     }
 }

When I start the level, and the ceiling is immediatly overhead, distToRoof registers as .28 For whatever reason, when the player is farther down from the ceiling, the distToRoof decreases by a small amount ins$$anonymous$$d of increasing.

Show more comments
avatar image Ian9921 · Jun 04, 2016 at 05:56 AM 0
Share

Thanks for trying to help, although I could not get your suggestion to work. I found my own simple way of doing it. I put an invisible cube above the player which, on trigger enter, would change a specific variable disabling flight. So, if the player ever got too close to the ceiling, the cube's code would trigger and stop them from going higher.

avatar image Wolfrik_Creations Ian9921 · Jun 04, 2016 at 04:03 PM 0
Share

Oh, sorry my solution didn't work.

If you want, you could click "$$anonymous$$ore..." next to your comment and turn it into an answer.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

How do you Place/Spawn a GameObject or Prefab in front of Player 2 Answers

Enemy spawn script/player position(java/js) 1 Answer

Climb animation is glitchy and isnt working properly 0 Answers

How to undo cancel Invoke 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