Rotate To Face
wij_man
Member Posts: 66
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!
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!
Comments
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.
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?)
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
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!
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!
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?
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.
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
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.
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!
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?
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.)
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...
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)
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.
Thanks again for all of your help!
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.
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!
Thanks though!
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.
Thanks for all of your help!