Search Unity

change a rigidbodies direction faster

Discussion in 'Scripting' started by Mike L, Mar 23, 2013.

  1. Mike L

    Mike L

    Joined:
    Sep 14, 2010
    Posts:
    1,035
    I have a game were the player is a rigidbody, the game is in a space environment, so there is no actual gravity affecting the player, and to make the game realistic, I'm using a constant force to apply force to the player to move them around, and there is no drag on the player so they can continue in the direction they were going. the only problem is its really difficult to change the players direction, like if they are going forwards, and you want to almost immediately go the other way, wether they turn around or simply press the opposite button, or if the player is going forwards and they move the mouse to turn were they are looking while holding down w they keep going the same direction they were going while slowly moving the new direction as well. I know whats going on here, but i dont know how to modify it do what i want. any suggestions would be nice
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Perhaps have it apply the force in the new direction more powerfully if the old direction is greater than a certain angle away?
    Use some combo of Vector3.Dot, or Vector3.Angle.
     
  3. Mike L

    Mike L

    Joined:
    Sep 14, 2010
    Posts:
    1,035
    that doesnt really work unfortunately, i need to have the player decelerate and accelerate at the same time, and im not sure how to do this. i need them to decelerate (i could apply a force to counteract it, though the main problem ive had with that (ive tried it) is keeping track of the direction the force should be applied in and how much force should be applied). deceleration is the only problem im having. I dont think i can really apply drag in this situation is the problem, because that would affect all degrees of movement....