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 cj31387 · Jul 30, 2012 at 07:56 AM · triggergravityfirst person controller

First Person Controler and Water wont effect gravity

I'm using the standard asset First Person Controller. I set up some water and made the water a cube and made that collider a trigger. I want to make it so when the character falls down into the water there is no gravity so he can start swimming. But when I use

void OnTriggerEnter(Collider other) { other.attachedRigidbody.useGravity = false; } nothing happens, the gravity doesn't stop but if i do just

 OnTriggerEnter(Collider other)
 {
     Destroy(GameObject);

 }

then when the character hits the water it works and he gets deleted. So I don't know why the gravity wont turn off in the first example. The only thing I can think of is all the scripts on the First Person Controller are in Java, and my scrips are in C#. Are java and C# compatible together in unity?

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

Answer by ScroodgeM · Jul 30, 2012 at 08:44 PM

attach this to object with trigger that simulates water. on enter to trigger character controller's speed is set to zero and gravity is disabled. on exit gravity is enabled again.

using UnityEngine; using System.Collections;

public class WaterZone : MonoBehaviour { void OnTriggerEnter(Collider other) { CharacterMotor cm = other.gameObject.GetComponent(); cm.SetVelocity(Vector3.zero); cm.movement.gravity = 0f; } void OnTriggerExit(Collider other) { CharacterMotor cm = other.gameObject.GetComponent(); cm.movement.gravity = 10f; } }

Comment
Add comment · Show 8 · 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 cj31387 · Jul 30, 2012 at 08:56 PM 0
Share

Yeah I do have a NullReferenceException WaterNoGravity.OnTriggerEnter on the line for useGravity = false .

I'm pretty new to program$$anonymous$$g and I've never used triggers before. I don't understand how this should connect to the player.

avatar image ScroodgeM · Jul 30, 2012 at 09:01 PM 0
Share

rather you have no rigidbody attached to collider you get in method. insert 'Debug.Log(other.gameObject.name)' to be sure you hangle correct object.

avatar image cj31387 · Jul 30, 2012 at 09:10 PM 0
Share

First Person Controller UnityEngine.Debug:Log(Object) WaterNoGravity:OnTriggerEnter(Collider) (at Assets/Assets/Scripts/WaterNoGravity.cs:8)

avatar image ScroodgeM · Jul 30, 2012 at 09:28 PM 0
Share

just found that First Person Controller doesn't use a rigidbody. so you need something like

void OnTriggerEnter(Collider other)
{
CharacterController cc = other.gameObject.GetComponent<CharacterController>();
cc.velocity = Vector3.zero;
Character$$anonymous$$otor cm = other.gameObject.GetComponent<Character$$anonymous$$otor>();
cm.Gravity = 0;
}
avatar image cj31387 · Jul 30, 2012 at 09:34 PM 0
Share

Yeah that's what I thought actually, I was looking at the FirstPersonController front to back and could not find a rigidbody anywhere. CharacterController is read only, and Character$$anonymous$$otor doesnt have a gravity field but ill look into it.

Show more comments

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing the objects rather than time. 2 Answers

How reliable are isGrounded checks? 1 Answer

Low gravity on trigger. 2 Answers

Trigger with Gravity + Collision 2 Answers

Trigger gravity by external collider 2 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