Page 3 of 3 FirstFirst 123
Results 21 to 23 of 23
  1. #21
    Join Date
    Jan 2003
    Location
    McBride, BC Canada
    Posts
    905
    I created the effect of rotating the ship when moving and the code I used is below. It actually turned out quite nice I think.


    Declare
    private static float TempRot;
    private static float TempPos;

    In Update Add
    //Amount to move and rotate
    Player.TempRot = (transform.position.x - Player.TempPos) * -10;
    Player.TempPos = transform.position.x;

    float amtToMove = Input.GetAxis("Horizontal") * PlayerSpeed * Time.deltaTime;
    transform.rotation = Quaternion.AngleAxis(TempRot * 10, Vector3.up);

    transform.Translate(Vector3.right * amtToMove, Space.World);

  2. #22
    Join Date
    Dec 2005
    Posts
    105
    Quote Originally Posted by gryfindor1 View Post
    UPDATE: Just trying out some more stuff for the space ship rotation on movement. I tried this bit of code here.

    while (Input.GetKeyDown("right"))
    {
    transform.Rotate(Time.deltaTime, 0, 0); (supposed to rotate object on X axis by 1 degree...I'd like to know how can do more)
    }

    However, the Engine just hangs and stops responding a soon as I press the movement key....its fine as long as I fire, but as soon as I touch movement...boom. Is this because I've placed it in the Update function and it's too much for the Engine to handle?(Sounds fishy)
    How that code is currently set up when you hit a movement key the engine will go into an infinite loop. The while statement will always be true for that frame/update. The input is sampled once before the update then does not change for the duration of the update. Instead of an while statement just use an if statement.

    For most of the other stuff I can't help you. I haven't opened Unity for a few weeks, life has gotten in the way.

  3. #23
    Join Date
    Dec 2010
    Posts
    13
    @jjstanley: Ill sample that code as soon as I get back to my PC...thanks for the help mate.

    @jjbird: Yeah I thought there was an infinite loop happening in there. I just thought that when I hit the key, it will rotate until I leave it...but I was wrong there.

    I'll give the if statement a go, though stanley's code looks neat as well. Anyone got any ideas on the message appearance which I mentioned earlier?

  4. #24
    Join Date
    Oct 2016
    Posts
    0
    Thanks for your sharing. Your article is very useful, it gives me more understanding. - temple run 2

  5. #25
    Join Date
    Oct 2016
    Posts
    0
    This blog is so nice to me. I will continue to come here again and again. Visit my link as well. Good luck - fnaf sister location

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •