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 Poxican · Oct 29, 2012 at 03:16 PM · gravitymouselookcollisionscollidecharacter motor

How to get collisions working on a flying controller?

I have a section in my game where the player enters a maze, colliding with a trigger that essentially disables gravity. They can then fly around in the maze. I am using the FPS Character Controller.

The problem is, the player no longer collides with anything. I've put a rigidbody on the controller, but no good.

The trigger disables the "Character Motor" script, the "MouseLook" on the Controller, and the "MouseLook" on the camera. The following code is then enabled, enabling free flight:

 var turnSpeed = 10.0;
 var moveSpeed = 10.0;
 var mouseTurnMultiplier = 1;
 
 private var x : float;
 private var z : float;
 function Update () 
 {
     // x is used for the x axis.  set it to zero so it doesn't automatically rotate
     //x = 0;
 
     // check to see if the W or S key is being pressed.  
     z = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed * 10;
 
     // Move the character forwards or backwards
     transform.Translate(x, 0, z);////
 
     zx = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed * 10;
 
     // Move the character forwards or backwards
    transform.Translate(zx, 0, 0);  ////
 
     // Get the difference in horizontal mouse movement
     x = Input.GetAxis("Mouse X") * turnSpeed * mouseTurnMultiplier/10;
     y = Input.GetAxis("Mouse Y") * turnSpeed * mouseTurnMultiplier/10;
 
     // rotate the character based on the x value
     transform.Rotate(-y, x, 0);   //transform.Rotate(-y, x, 0); <<<
 
 }

So I can then fly around fine, but don't collide with anything.

I've been trying to figure this out for two days. I've read every single scrap of information I can on Answers etc. but I'm just not able to get it to work.

If I fly to a point within the maze, and then switch the Mouselooks and Controller back on, and the above script off, gravity re-engages, the character falls, and collisions are back to normal.

Any ideas? This is making me feel really stupid and I'm sure it can't possibly be that complicated....

Thanks in advance ;)

Comment
Add comment · Show 3
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 GC1983 · Oct 29, 2012 at 03:54 PM 0
Share

Youre using transform.translate. That ignores physics. Use something like Vector3.Lerp() ins$$anonymous$$d.

avatar image FLASHDENMARK · Oct 29, 2012 at 04:05 PM 0
Share

I'm pretty sure Vector3.Lerp won't help in this case. Use Rigidbodies or a Character Controller.

avatar image GC1983 · Oct 29, 2012 at 04:21 PM 0
Share

It can certainly fix it, my game uses it. But calling for the CC can work too.

1 Reply

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

Answer by lil_billy · Oct 29, 2012 at 04:58 PM

Ive actually solved this problem

Like GC said dont use translate because that ignores collision whenever you wish to create movements that respect collisions: use either charactercontroller.move or the rigidbody move system. rigidbody is good because it will allow you to have very physics grounded motions.

however there are problems: if you use rigidbody motion it requires a solid collider to handle its collisions. If you have both a character controller movement script and a rigidbody movement system. The character controller will fight with whatever solid collider you have and cause obnoxious problems. In my own script I am dealing with this by disabling everything used for the controller system when i switch to my flight system.

Now I dont know what you mean by flight in regards to a maze. but when doing mine I found this to be an AWESOME starting point to which i modded the hell out of: http://forum.unity3d.com/threads/42616-Flight-Sim-Starter-Script-%28Files-Included%29

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

12 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

Related Questions

Mouse Look from any Orientation 0 Answers

Calculating collision behavior while using lerp 0 Answers

How do I make c# script to have a player not fall through a platform? 3 Answers

I Have a problem with graphics and physics 1 Answer

Problem with Look at mouse in a spherical world 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