Rotate To Face

wij_manwij_man Member Posts: 66
edited August 2012 in Working with GS (Mac)
Hi,

I have a rectangular actor (player) which is controlled using the keyboard. I'm using constrain to constrain my players rotation to "vectorToAngle( self.Motion.Linear Velocity.X , self.Motion.Linear Velocity.Y )-90" which works great. The issue is that it seems a little jumpy, of the player moves left is faces left, but if they then move right the image just flips immediately. I'd like the rotation to be fast and smooth, not that sudden...

I've tried using rotate to position but I can't figure out the right formula; my formula at the moment makes my actor rotate right when right is pressed when my player is already facing right (it then faces down).

I've also tried interpolate but my actor always then rotates clockwise and spins for no reason, face left, right, left ends up in a couple of 360s.

Has anyone else tried this and perhaps overcome this issue? I'm sure there's a way of doing it, one of you guys must know it! :)
«1

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited August 2012
    One way that does not involve constraining the rotation is:

    When right key:
    -- Rotate to Angle: .01, Relative to: scene, Speed: 900, Run to Completion, Stops on destination
    -- Change Attribute: Self.Motion.LinearVelocity.X To: 200

    When left key:
    -- Rotate to Angle: 180, Relative to: scene, Speed: 900, Run to Completion, Stops on destination
    -- Change Attribute: Self.Motion.LinearVelocity.X To: -200

    Note: The ".01" is to make the actor rotate clockwise. If you set it to "0" instead, the actor will rotate counterclockwise when it has to start from 180.
  • wij_manwij_man Member Posts: 66
    What about the angles in between? So diagonal up/left, up/right...
  • wij_manwij_man Member Posts: 66
    I wanted something generic enough to work for all angles, not just up/down/left/right...
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Oh... you didn't mention anything but using the left and right arrow keys.

    Do you mean that you want the actor to rotate smoothly clockwise when you hit the right arrow key. (So that if you hold an arrow key down long enough, it will rotate back around to its starting place?)
  • wij_manwij_man Member Posts: 66
    No, Up moves forward, down moves back, right moves right and left moves left. I would like the player to rotate to face the direction they are moving. I have done this. I would like the player to rotate smoothly, so if they are facing up and you hit right, they should rotate clockwise 90 degrees. If then they hit the up key they should rotate counter-clockwise 90 degrees. The rotate to face I am using works, but it is too sudden...
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited August 2012
    Try this:

    When right key:
    -- Rotate to Angle: .01, Relative to: scene, Speed: 900, Run to Completion, Stops on destination
    -- Change Attribute: Self.Motion.LinearVelocity.X To: 200
    -- Change Attribute: Self.Motion.LinearVelocity.Y To: 0

    When left key:
    -- Rotate to Angle: 180, Relative to: scene, Speed: 900, Run to Completion, Stops on destination
    -- Change Attribute: Self.Motion.LinearVelocity.X To: -200
    -- Change Attribute: Self.Motion.LinearVelocity.Y To: 0

    When up key:
    -- Rotate to Angle: 90, Relative to: scene, Speed: 900, Run to Completion, Stops on destination
    -- Change Attribute: Self.Motion.LinearVelocity.X To: 0
    -- Change Attribute: Self.Motion.LinearVelocity.Y To: 200

    When down key:
    -- Rotate to Angle: 270, Relative to: scene, Speed: 900, Run to Completion, Stops on destination
    -- Change Attribute: Self.Motion.LinearVelocity.X To: 0
    -- Change Attribute: Self.Motion.LinearVelocity.Y To: -200
  • wij_manwij_man Member Posts: 66
    Hi,

    That works fairly well, but diagonals don't work, which means that points in between won't work. Unless I got something wrong...

    Also, thanks for your help so far, it feels as though we're getting closer! :)
  • wij_manwij_man Member Posts: 66
    Also the linear Velocity stuff doesn't seem to do anything; it acts the same when off...
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    How would it do diagonals? You didn't mention how diagonals would work.
  • wij_manwij_man Member Posts: 66
    Sorry. I'm trying to explain, just not doing a very good job!

    The player can move in ANY direction (using the arrow keys), this will later be mapped to another input source so 360 degree rotation is important.

    I want the actor to face the direction it is moving. I don't want the image to "flip" suddenly (if the player presses left then right for example). If for example the player is facing 0 (assuming 0 is up and 90 is right), then moves to 64, I would want a smooth rotation from 0 to 64 (all in numbers in degrees btw).

    Thanks again!
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    So you do want the actor to rotate smoothly clockwise when you hit the right arrow key. (So that if you hold an arrow key down long enough, it will rotate back around to its starting place?)
  • wij_manwij_man Member Posts: 66
    Nope. I don't know how to explain it differently. I'll try one more time (I'm not good at this!).

    Forget arrow keys for a moment and imagine that the control mechanism is tilt. In fact that's the perfect way to view it, download Tilt To Live and see how that is controlled. The player always faces the direction it is moving, but when there is a sudden change in direction the rotation (going one direction and then suddenly the opposite) the rotation of the player is smooth. Tilt To Live is the best example I can find of this on my phone.

    So (still talking tilt) if the player is facing 0 and then moves to 64 the player rotates through 0,1,2,3,4,etc all the way to 64.

    Hopefully this helps, if not I may have to give up trying to explain and just play around with it for a week till I figure it out, or realise it can't be done!

    If this can'y be done with a keyboard, what tilt rules would I need to make this work in that way?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    OK -- I just watched a trailer for tilt to live.

    So basically you are using the arrow keys to simulate tilting the device?

    What are the behaviors you are using for the arrow keys? (In terms of movement, not direction.) Perhaps if I can replicate what you are doing, I will be able to help.
  • wij_manwij_man Member Posts: 66
    I've uploaded my whole project (I only started a few days ago and I'm slow... so nothing private here :-)

    http://www.sendspace.com/file/lpppos

    Hopefully this will give you an idea of what is going on! :)

    But to answer your question I'm using "move" with a move type of additive (not 100% sure what this does but TSB used it in one of his vids!). And yeah, I'm using the arrow keys to save me having to put the game on my device every 30 seconds to test something out. Which brings me to a different question... My iPhone is synced with my Windows Laptop but developing with GS on my mac, is the quickest way to get an app on my phone to email/usb it across and put it on my phone without using my mac as my main itunes library?

    Thanks again
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited August 2012
    Based on the trailer for tilt to live, I'd suggest the following:

    When right key:
    -- Accelerate: 0, Relative to scene, Acceleration: 100

    When left key:
    -- Accelerate: 180, Relative to scene, Acceleration: 100

    When up key:
    -- Accelerate: 90, Relative to scene, Acceleration: 100

    When down key:
    -- Accelerate: 270, Relative to scene, Acceleration: 100

    Timer: Every .025 seconds
    -- Rotate to Angle
    ----Angle: vectorToAngle( self.Motion.Linear Velocity.X , self.Motion.Linear Velocity.Y )
    ----Relative to scene
    ----Speed 2000 (or whatever)
    ----Run to completion (yes)
    ----Stops on destination (no)


    By the way, in gamesalad the "0" angle is pointing right ---->. Make sure your graphics are drawn pointing in that direction to begin with. It will make it much easier to rotate things correctly when they all begin at the "0" angle.

    90 degrees is straight up ^^^^^,
    180 degrees is pointing to the left <------,
    and 270 degrees is pointing down.
  • wij_manwij_man Member Posts: 66
    For some reason when I stop moving it resets the position of the actor to facing right. Also going from facing right to down it rotates 270 degrees anti-clockwise instead of taking the logical route! I know this seems minor, but it will just look plain crazy in a game!

    Please stop putting down all the details for all the keys, I feel bad! Just tell me roughly what I need to do, stop making so much effort! Although it is very much appreciated! :)
  • wij_manwij_man Member Posts: 66
    edited August 2012
    Ignore that last comment. What the hell is acceleration, dumb, dumb question. I'll elaborate but I'll post this first so you don't take time replying!

    Can I control the speed of acceleration? Using the acceleration attribute it feels too much as is it's being controlled by it's mass rather than a control mechanism. By this I mean that I feel as though I have much, much less control than using the "move" method. Can I make Accelerate act like Move?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Acceleration is like stepping on the gas (the accelerator pedal). The longer you press, the faster you go.

    If this case its more like hitting four different thrusters on a spaceship. One on each side of the ship.

    Slow acceleration down and see if it gives you better control. (Change from 100 to 50 and see if it helps.)
  • wij_manwij_man Member Posts: 66
    I upped acceleration to 2000 and put a max speed of 200, then I put a set linear velocityx/y to 0 when the key is lifted (on the otherwise clause), which is very close to what I want. But...

    1) The actor keeps moving after I left go of a key, it slows to a crawl, but clearly still moving.
    2) This actor now bounces off of walls. I have other objects which should bounce off of the walls, but the tank didn't do this when I was using Move, so I don't know how to stop it bouncing like a mad man...
  • wij_manwij_man Member Posts: 66
    Setting the density of the actor to 99999999999 makes it not bounce, but instead shake when it hits a wall...
  • wij_manwij_man Member Posts: 66
    Fixed both issues... One last thing. When I move diagonally now the actor faces sideways. Shall I upload the project again so that you can see what's going on?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited August 2012
    By mentioning other issues, does this mean the "rotate to face" challenge is working like you want? (Often its best to solve one thing at a time!)
  • wij_manwij_man Member Posts: 66
    edited August 2012
    FFS - GameSalad just crashed. Still have the diagonal issue I just mentioned, but all of my rules have gone! I save after EVERY change to make sure this doesn't happen! Damn, damn, damn! I'l starting to think I should go and use Unity! This is so annoying!!!!! I have to make all of my rules again!

    Also, in fixing Rotate To Face we've made more issues. But no, Rotate To Face isn't working (see post from 6:16AM; my last post)
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Oops! That can be annoying.

    Make incremental backups. Name each backup with a slightly higher version number (Tankv1, Tankv2, Tankv3, etc.).

    Time for me to sign out. Good luck with your project. It looks like fun.
  • wij_manwij_man Member Posts: 66
    Thanks! Please come back and finish what you started! It's 06:25AM here... I'm only here because of you! So you'd better come back! :-P

    Thanks again for all of your help! :)
  • wij_manwij_man Member Posts: 66
    Rotating the shortest way around: ((vectorToAngle( self.Motion.Linear Velocity.X , self.Motion.Linear Velocity.Y )+180)%360)+90

    phew, that was hard....

    The last side effect of changing to accelerate is that my actor now bounces... I have set Bounciness (people say restitution, but in my GS it says Bounciness...) to 0 on both the wall and the actor, but the actor still bounces.
  • delorianhayzedelorianhayze Member Posts: 55
    For the bouncing issue- to the best of my knowledge this is a fault of the current GS engine. The only way for an object to not bounce is for them to be set to NO MOVEMENT. Obviously this presents problems. The only way that I've heard for an object/actor to not be affected by another object is to...
    1.) Constrain an actor to a coordinate/path. I.E. You could constrain a Paddle in Pong to the X axis. This will ensure it doesn't bounce off a certain desired area (this doesn't help you btw)
    2.) Swap actors on the fly. When an object gets hit have it SWAP quickly with a clone object that is set to NO MOVEMENT and then swap back to it's movement clone (this is probably also not helpful).

    I'm by no means an expert and there's a solid chance my info is wrong, but this issue has seemed to be an issue with many people. Again it appears to be an issue with the engine the current GS is using.
    I'm sure you've done this but you could try to ensure that your density and bounciness on the main actor is stronger and sturdier than your opposing object. I believe you have done this however. Be careful not to set your density so high as it may cause GS to crash or underperform.

    WHAT I WOULD DO:
    Again I'm no expert here. Not at all. But here's what I would do if it was crucial that my main character not move when it's hit.
    1.) Have an invisible actor constrained to the x y of your main character. Again making it invisible.
    2.) Rule says whatever object that hits the invisible object (not your main actor) bounces off of that. Thus giving the illusion it's bouncing off your main character, but your main character looks unaffected.
    3.) Some kind of rule that once the invisible object has been hit, to reset it's position back to the position of the main character's x y.

    Hope some of this helps!
  • wij_manwij_man Member Posts: 66
    Thanks, I'm going to swap to use Unity for this game now. Which is a pain, but GS just doesn't seem to have enough functionality for any of the games I want to make, or in this case, it's too buggy...

    Thanks though! :)
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @wijman -- glad to see you found how to rotate the shortest way. (I was waiting for that one to come up.)

    Have you fixed your rotatable images so they initially point to 0 degrees. (Which is directly to the right ----> in GameSalad.)

    "Bounciness" used to be called "Restitution" the new word is more descriptive.
  • wij_manwij_man Member Posts: 66
    @RThurman - It turns out that my timer based rotate to face method is the problem (why my actor bounces). I'm not 100% why, but the GS team have verified that it's not a bug and that method will cause this type of behaviour. I'll still be around the forums for a while and I'll try to think of another game I can make with GS, but for now the two games I'm making have to be done the hard way!

    Thanks for all of your help! :)
Sign In or Register to comment.