• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Use Mouse as Direction for Character Movement? 0 Answers

Check If Any Objects In Your Game Are Colliding? 1 Answer

How to enable gravity on prefab after collision? 0 Answers

Calculating collision behavior while using lerp 0 Answers

Mouse Look from any Orientation 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges