Search Unity

[Solved ] Cant get an simple sliding collision to work :(

Discussion in 'Scripting' started by GamersHeaven, Mar 7, 2010.

  1. GamersHeaven

    GamersHeaven

    Joined:
    Feb 15, 2010
    Posts:
    88
    Why does the variabels x-y-z turn to 0 everytime the ship collides with something ?
    Have bin working on this all day but as an noob at unity scripting :?
    I even tryed to use pure physics, but it simply screwed the ships rotation around without even rotating the ship mesh?
    Code (csharp):
    1.  
    2. var isColliding = false;
    3.  
    4. function OnTriggerStay() {
    5.     isColliding = true;
    6. }
    7.  
    8. function OnTriggerExit() {
    9.    isColliding = false;
    10. var x = 0.0;
    11. var y= 0.0;
    12. var z = 0.0;
    13. }
    14.  
    15. function Update() {
    16.  if(isColliding==false){
    17.  Debug.Log("iam freeeee");
    18. var x = transform.position.x;
    19. var y= transform.position.y;
    20. var z = transform.position.z;
    21. Debug.Log(x+"  "+y+"  "+z);
    22. }
    23. else{
    24. //transform.position = Vector3(xxx,yxx,zxx);
    25. Debug.Log(x+"  "+y+"  "+z);
    26. }
    27. }
    28.  
    EDITED_____________________________________________
    Ok :D
    Finally figured this one out a bit :wink:
    Code (csharp):
    1.  
    2. var isColliding = false;
    3. var x = 0.0;
    4. var y= 0.0;
    5. var z = 0.0;
    6.  
    7. function OnTriggerStay() {
    8.     isColliding = true;
    9. }
    10.  
    11. function OnTriggerExit() {
    12.    isColliding = false;
    13. }
    14.  
    15. function Update() {
    16.  if(isColliding==false){
    17.  Debug.Log("iam freeeee");
    18. x = transform.position.x;
    19. y= transform.position.y;
    20. z = transform.position.z;
    21. Debug.Log(x+"  "+y+"  "+z);
    22.  
    23. }
    24. else{
    25. transform.position = Vector3(x,y,z);
    26. Debug.Log(x+"  "+y+"  "+z);
    27. }
    28. }
    29.  
    My new problem is that the ship gets stuck to the object it collides with :?
    Simply a bit more work nead to be done :oops: