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 Therian13 · Nov 18, 2014 at 10:07 AM · physicscharactercontrolleraddforce

make addforce ignore player controller?

Hello Everyone, I am currently working on a 3d FPS game that enables the player to enter and pilot a underwater submarine pod. The pod uses the addRelativeForce on it's rigidbody since it slowly accelerates and drags as if underwater.

The problem is, my character's player controller is being seen as an outside force, even if I add the character (child) to the ship (parent) in the hierarchy.

If the ship does any sort of movement such as turning or ascending, the player is able to push against the ship and make it slow down or suddenly fly off into a random angle. The player has a rigidbody as well but with 0 mass,drag, and angular drag.

Does anyone know if there is a way to make the character controller unable to affect the addforce? I know I can use "position.transform.y" but then the ship doesn't react to outside colliders (such as rocks)..

Thank you for taking the time to read this, and I hope someone can point me in the right direction.

I have attached my script for the addforce in case it is needed.

 #pragma strict
 
 var theplayer: Transform;
 var theplayercamera: GameObject;
 var theplayermovement : FPSWalkerEnhanced;
 private var drawGUI = false;
 var thechair : GameObject;
 var theShip : GameObject;
 var respawnTransform : Transform;
 var respawnTransform2 : Transform;
 var seatOccupied : boolean = false;
 var chairCamera : GameObject;
 
 var driveCommands : startingshipdrivingscript;
 
 
 function Update () 
 {
     if (drawGUI == true && Input.GetKeyDown(KeyCode.E) && seatOccupied == false)
     {
         enterchair();
     }
     else if ((Input.GetKeyDown(KeyCode.E) || Input.GetButton("Jump"))&& seatOccupied ==true)
     {
         exitchair();
     }
     if (seatOccupied == true)
     {
         drawGUI = false;
         driving();
     }
 }
 
 function OnTriggerEnter (theCollider :Collider) 
 {
     if (theCollider.tag == "Player" && seatOccupied == false)
     {
         drawGUI = true;
     }
 }
 
 
  function OnTriggerExit (theCollider : Collider)
  {
      if (theCollider.tag == "Player")
     {
         drawGUI = false;
     }
  }
 function OnGUI ()
 {
     if (drawGUI == true)
     {
     GUI.Box (Rect (Screen.width*0.5, 400, 300, 26), "Press E to Pilot");
     }
 }
 
 function enterchair ()
 {
     seatOccupied =true;
     
     theplayer = GameObject.FindGameObjectWithTag("Player").transform;
     theplayer.GetComponent(MouseLook).enabled = false;
     theplayermovement = theplayer.GetComponent(FPSWalkerEnhanced);
     theplayermovement.walkSpeed = 0;
     theplayermovement.runSpeed = 0;
         theplayercamera = GameObject.Find("Main Camera");
     theplayercamera.SetActive(false);
     chairCamera.SetActive (true);
     
     
     theplayer.parent = thechair.transform;
         theplayer.transform.position = respawnTransform.position;
     theplayer.transform.rotation = respawnTransform.rotation;    
 }
 
 function exitchair ()
 {
     seatOccupied =false;
     
     theplayer = GameObject.FindGameObjectWithTag("Player").transform;
     theplayer.GetComponent(MouseLook).enabled = true;
         theplayermovement.walkSpeed = 6.0;
     theplayermovement.runSpeed = 11.0;
     theplayercamera.SetActive(true);
     chairCamera.SetActive (false);
     theplayer.parent = theShip.transform;
         theplayer.transform.position = respawnTransform2.position;
     theplayer.transform.rotation = respawnTransform2.rotation;    
 }
 
 function driving()
 {
 if (Input.GetKeyDown(KeyCode.W))
 {
  driveCommands.gear +=1;
 }
  if (Input.GetKeyDown(KeyCode.S))
 {
  driveCommands.gear -=1;
 }
 if (Input.GetKeyDown(KeyCode.D))
 {
  driveCommands.turngear +=1;
 }
  if (Input.GetKeyDown(KeyCode.A))
 {
  driveCommands.turngear -=1;
 }
 if (Input.GetKeyDown(KeyCode.R))
 {
  driveCommands.raiseup +=1;
 }
 if (Input.GetKeyDown(KeyCode.F))
 {
  driveCommands.raiseup -=1;
 }
 
 }

Comment
Add comment · Show 4
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 incorrect · Nov 18, 2014 at 10:46 AM 1
Share

As I know character controller can not be used with rigidbody and it's main idea is to give an easy way to make games to those guys who lack knowledge of physics or just are too lazy to make things right way. :)

So to fix your problem, as I understand, is to disable character controller when you are controlling your sub and enable it when you leave the pilot's seat.

avatar image Therian13 · Nov 18, 2014 at 10:56 AM 0
Share

my apologies, I meant that it causes that issue when he walks around in the sub. You can exit the pilot seat and walk around to repair parts of the submarine that get damaged or to leave the sub.

avatar image incorrect · Nov 18, 2014 at 01:04 PM 0
Share

You know that character controller ignores physics and that is how it is supposed to work? Just make a simple character with rigidbody and collider, it's not that hard or will take long time, but solves your problem.

avatar image Therian13 · Nov 19, 2014 at 05:20 AM 0
Share

I got ahold of a character controller script, but now the character doesn't move when the ship moves or rotates. He just sort of slides around in place until he hits a wall.

I increased the floor material friction, so he doesn't seem to slide around, but still doesn't rotate when the ship does...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nanako · Nov 24, 2014 at 01:45 PM

If it's not what you're already doing; i'd solve this by parenting the player to the sub.

And also by increasing the mass of the sub significantly

I don't think objectd can exert forces on their parent like that, but i could be wrong. Even if so, there's other things you could do to compensate. IMO passengers and drivers should always be parented to a vehicle they're in, so that it becomes their frame of reference.

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Calcuation Difference Between AddForce and AddForceAtPosition 1 Answer

Movement with AddForce: Wrong Direction 2 Answers

Erratic Physics behaviour while testing in 2 computers 0 Answers

Error on checking collision or code desync? 0 Answers

Character Controller collision speed 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