Player rotation
Hey all
I'm in the process of creating my first game and basically I have an aircraft which constantly flys and you simply rotate it up and down while shooting at other aircraft.
I'm basically completely ripping off The island of dr dystructo
I've managed to sort out the rotation while flying my problem is the animation.
Using the animate fuction it animates through the frames when the key is pressed but instantly flips back to the first image when the key is released. I need it to stay in the last frame used when the key is released effectively meaning theres a different image for every angle of the plain which is stays in until a key is pressed again.
Also I have the scene wrap x and y checked so the plain appears on the left if it flys off the right but is happens instantly is there a way to delay it a little so it flys of the right side of the screen dissapears for a second then flys in from the left.
Any help would be much appreciated.
Comments
If you name all of your animation frame image files sequentially (e.g. plane1.png, plane2.png, plane3.png), then you can create a manual animation:
When key is pressed
Timer every 0.1 seconds
Change Attribute self.counter to mod(self.counter,20)+1
Change Attribute self.Image to "plane"..self.counter
This assumes you have 20 frames. If you have less/more, adjust the number 20. You can, of course, also adjust the timer speed.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Make your scene a little bit bigger, for example if you have an iPad sized project (1024 x 768), the - for example - change your scene size to 1424 x 768, this means the actor will fly off the righthand side and then still travel for another 400 pixels before it appears back on the left.
Thanks for the replys.
So is the self counter a attribute I create myself under player 1 actor?
//
Yes. You can use an integer for that.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Can't seem to get it to work.
Put the code exactly as you said:
When key is pressed
Timer every 0.1 seconds
Change Attribute self.counter to mod(self.counter,20)+1
Change Attribute self.Image to "plane"..self.counter
but the image doesnt change.
I even went as far as creating a rule of each angle saying if self.rotation = this angle change self image to plane3 etc.
Still didnt work, image doesnt change?
Thats worked great btw Socks, thanks for that
Is your image sequence called "plane"... ? And have you got exactly 20 frames ?
Yes, I changed to 8 frames and have plane1 - plane8 so
Change Attribute self.counter to mod(self.counter,8)+1
Can we see the rules (a screenshot would be ideal), you may have made an error, there's no real way to tell without seeing the rules.
Actually kinda managed to get it to work. Put the rules in the wrong place.
Only problem is if I keep the key pressed down it still cirles through the frames.
Kinda thinking this will be to complicated.
Ideally what I want is keeping the key pressed the plane will continuely just rotate in a circle with a default image for every angle, don't even mind if it jumps say from 0 to 25 degrees have a image for that then next angle is say 50, image for that so a max of say 15-16 angles in a circle with a default image for each.
Literally have no idea how to achieve this and it all sounds a bit too much for something that seems like it should be simple in exercution.
Yeah, it's really easy to put something in the wrong place or miss a comma or a bracket (or whatever), and spend hours trying to work out what you've done wrong, we've all done it numerous times !
Yes, with the logic . . .
When key is pressed
--Timer every 0.1 seconds
----Change Attribute self.counter to mod(self.counter,20)+1
----Change Attribute self.Image to "plane"..self.counter
. . . the actor will cycle through the frames as long as you hold the key down.
I don't understand what any of that means !?
OK heres a short vid of what I meant and ideally what I'd love to achieve. The plane rotates in circles with just the right or left arrow key held down and changes animation/images for each angle.
But as I said I have no idea how to achieve this
You could just constrain the actor's image to its angle (rotation). Quick demo attached below: (left and right arrow keys steer)
Thats exactly what I want thanks a lot
Would of had no clue how to use constrain, still got a lot to learn.
Think of Constrain as a Change attribute action that happens on every code cycle / 60 times a second, so essentially it is constantly changing whatever atribute you have it pointed at.
Here's another couple of quick ideas, rather than have the plane stop on a static frame when you let go of the left or right arrow keys, the plane should gently roll (bank) left and right (I've used a sine wave to oscillate it back and forth through 30° of banking) . . . also rather than the plane dropping instantly out of its loop when you let go of the left or right arrow keys, I've made it ease into level flying instead, it feels a lot more 'floaty' now . . . might not be right for what you are doing, but I was just playing around with this for fun . . .
File attached
Dude you are a legend, cant thank you enough.