Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Space Flight

Discussion in 'Scripting' started by mbahadirb, Jul 28, 2010.

  1. mbahadirb

    mbahadirb

    Joined:
    Jul 8, 2010
    Posts:
    21
    Hi

    I am working on a space flight simulation and I have some questions to ask:

    First for roll movements(for rotation around Z) I added another axis and set keybord buttons as controllers. My problem is that my ship wont stop rolling after I stop pushing the button. I tried to stop rolling manually but didnt work.

    Second I want to add a mesh explosion animation as in 3Ds Max but I dont think it can be done. Should I model my ships in parts for explosion or is there a method that I miss.

    My simplified movement controls for your comment:
    Code (csharp):
    1.  
    2. var thrust = 10.0;
    3. var rotateSpeed = 1.0;
    4. var controller : CharacterController = GetComponent( CharacterController );
    5.  
    6. function Update(){
    7.         RotateAroundSelf();
    8. }
    9.  
    10.  
    11.  
    12. function FixedUpdate(){
    13.     rigidbody.AddForce( transform.forward * thrust );
    14. }
    15.    
    16.  
    17.  
    18. function RotateAroundSelf(){
    19.     transform.Rotate( Input.GetAxis( "Vertical" ) * rotateSpeed, Input.GetAxis( "Horizontal" ) * rotateSpeed, Input.GetAxis( "Pitch" ) * rotateSpeed );
    20.    
    21. }
    22.    
    23.  
    Thanks for the help in advance
    Bahadir Boge
     
  2. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    Do you mean that if you press one of the 'roll' keys and then release it (so that no keys are being pressed), the ship continues to rotate?

    If so, you might compare the setup for the 'roll' axis to the setups for the other two axes to make sure the roll axis is set up correctly. (I'm not sure if that's what's causing the problem, but it seems that if the smoothing values weren't set correctly, you could end up with the effect of continued motion when the key was released.)
     
  3. mbahadirb

    mbahadirb

    Joined:
    Jul 8, 2010
    Posts:
    21
    Thanks for the fast reply.

    I checked that and there is a difference. Vertical and Horizantal axises has type of Joystick and their Axis types are X and Y. My pitch axis has type of Key or Mouse Button(doesnt work at all when i changed this to joystick or scroll axis) and axis is 3th-8th axis(tried all: same result).
     
  4. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    It could be that the change of rotation is reacting badly with the physics engine. Generally, you should turn a rigidbody object by adding torque. There is an AddTorque function, but for a spaceship, you may it better to simulate thrust from orientation thrusters. You can do this by using AddForceAtPosition to push the rigidbody at a position away from its centre of mass (which will make it spin as well as move).
     
  5. mbahadirb

    mbahadirb

    Joined:
    Jul 8, 2010
    Posts:
    21
    AddTorque/AddForceAtPosition I will add these but my take some time to adjust. Course correction may need adjustment.
     
  6. cerebrate

    cerebrate

    Joined:
    Jan 8, 2010
    Posts:
    261
    you might want to also try increasing the angular drag. This causes rotating objects to slow down. By default it's very low, so for something not colliding with anything, will continue spinning for a while