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 Naminu · Aug 31, 2015 at 10:53 AM · rigidbodygravityfallinghover

If button is not pressed fall.

Hello! What I want to do is when my character floats to the right and collides with an invisible mesh, I want the player to fall down if the mouse button isn't pressed but if it is pressed while it's colliding it should continue to hover to the right!

I have done the hovering to the right script and I can't do the thing with the falling. Help plox?

C# if you can!

Comment
Add comment · Show 6
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 darthtelle · Aug 31, 2015 at 11:03 AM 0
Share

Could you post the code you have currently and the code you've tried?

avatar image Bob-The-Zealot · Aug 31, 2015 at 11:08 AM 0
Share

So which part has the problem?

avatar image darthtelle · Aug 31, 2015 at 11:11 AM 0
Share

When OnTriggerEnter is called, is the Hover component already enabled/attached? If it isn't, you're not enabling it when the mouse isn't clicked.

EDIT: Or rather you're disabling it? I see there's an exclamation point in your Input call which means if it's false. So you're disabling the Hover script?

avatar image Naminu · Aug 31, 2015 at 11:12 AM 0
Share

The one for falling. If I press the button it still falls. It must be a simple solution for that but I'm just blocked now Xd

avatar image darthtelle · Aug 31, 2015 at 11:18 AM 1
Share

OnTriggerEnter only occurs for one frame, so I have a feeling when it's called, the function is happening too quickly for the Input to register. You'd be better off looking at how triggers work and maybe making a system for the start of OnTriggerStay.

http://docs.unity3d.com/$$anonymous$$anual/CollidersOverview.html http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnTriggerEnter.html http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnTriggerStay.html

Either way, you're still disabling the Hover component when no input is received. Change that to true.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bob-The-Zealot · Aug 31, 2015 at 11:21 AM

Try changing your chick check to:
if (!Input.GetButtonDown ("Fire1"))
I'm not sure if that's the problem, but try it.

Comment
Add comment · 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
0

Answer by Naminu · Aug 31, 2015 at 11:04 AM

I managed to fix it! I'm gonna leave the scripts here in case someone else has my problem.

Falling Code.

 using UnityEngine;
 using System.Collections;
 
 public class Fall : MonoBehaviour {
 
     public Collider coll;
 
     // Use this for initialization
     void Start () {
     
 
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     
     void OnTriggerStay(Collider other) {
         if (!Input.GetButton("Fire1"))
         {
             other.attachedRigidbody.useGravity = true;
             other.GetComponent<Hover>().enabled = false;
         }
         else
         {
             other.attachedRigidbody.useGravity = false;
             other.GetComponent<Hover>().enabled = true;
         }
 
 
         
     }
 }
 

Hover Code

 public class Hover : MonoBehaviour {
 
     public float horizontalSpeed;
     public float verticalSpeed;
     public float amptitude;
 
     public Vector3 tempPosition;
 
 
     void Start () 
     {
         tempPosition = transform.position;
     }
 
     void Update () 
     {
         tempPosition.x += horizontalSpeed;
         tempPosition.y = Mathf.Sin (Time.realtimeSinceStartup * verticalSpeed) * amptitude;
         transform.position = tempPosition;
     }
 }
 
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 Naminu · Aug 31, 2015 at 11:28 AM 0
Share

Also, thank you darthtelle!

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

30 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

Related Questions

Detect if falling with custom gravity 1 Answer

Gravity is not working 0 Answers

Using rb.velocity causes low gravity. 2 Answers

3D Game RigidBody Problem 0 Answers

Strange gravity using rigidbody on vehicle 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