ΠΓΣ518: ΥΕΔΙΑΜΟ ΠΑΙΥΝΙΔΙΩΝ ΗΛΕΚΣΡΟΝΙΚΩΝ ΤΠΟΛΟΓΙΣΩΝ Δέζποινα Μιταήλ Σμήμα Πολσμέζων και Γραθικών Σετνών Σετνολογικό Πανεπιζηήμιο Κύπροσ Διάλεξη 12 Animation Βαζηθέο αξρέο γηα Game Animation 1. Cycles: Almost every game character animation should be a cycle The first and the last keyframe of each motion should match Examples: For walks, animate from left foot fall to left foot fall In an idle animation, have the character return to exactly the same pose as he began. 1
Βαζηθέο αξρέο γηα Game Animation 2. Cycles should be short For example, a common problem is the jump animation. In a non-game situation has a lot of great squash and stretch that when used in game means the character hasn't even gotten ready to jump before they should be in the air. This doesn't mean that good concepts of animation (i.e., squash and stretch) shouldn't be used in fact it's critical that they are. They just often need to happen quicker and subtler Exception: idle animation the animation a character does when it's waiting for other instructions. A longer idle animation keeps the repeating cycle from being quite so obvious. Βαζηθέο αξρέο γηα Game Animation 3. Do the animations in place For animations like walk, run, or jump, imagine that the character is on an invisible treadmill and while his feet are moving as though he's covering ground, he needs to stay put, walking in place. The actual translation of the character will take place programmatically and the character will move forward, backward, or side to side based upon user input. [Demonstration: frames 300-330 in the AegisChung_SingleMesh.mb] 2
Βαζηθέο αξρέο γηα Game Animation 4. Keep it in one file and note the range. There are actually different ways to attack this issue. On the one hand Unity allows you to import several files, each with its own animation. Then these animations can be called up later and assembled on one mesh. However, its easier to have all the animations created in one Maya file and take note of the ranges (idle: frame 1 240, walk: frames 300 330, etc.). Then when Unity imports the.fbx, you can tell Unity to interpret these different animation clips by defining the range of frames that that animation occurs in. This just keeps all the animations contained in one file and makes the housekeeping easier inside of Unity. 2 ηξόπνη γηα animation 1. Φηηάρλεηο ην animation κε εξγαιείν κνληεινπνίεζεο θαη ην εηζάγεηο ζην Unity 2. built-in animation system ηνπ Unity 3
1. animation με εργαλείο μονηελοποίηζης Animation ζην Μaya Animation ελόο απινύ αληηθεηκέλνπ Timeline bar ζην θάησ κέξνο Η θαηάζηαζε ηνπ αληηθεηκέλνπ κπνξεί λα θαζνξηζηεί όπσο αθνινύζσο επηιέγνληαο: Σν ρξόλν πνπ ζέινπκε λα θαζνξηζνπκε ηελ θαηάζηαζε Σν αληηθείκελν θαη ην ηνπνζεηνύκε ζηελ επηζπκεηή ζέζε Από ην menu-set Animation επηιέγνπκε ην Animate Set Key ή παηώληαο ην πιήθηξν S Η πην πάλσ δηαδηθαζία ζα δεκηνπξγήζεη έλα keyframe ζηνλ επηιεγκέλν ρξόλν, γηα ην επηιεγκέλν αληηθείκελν Γεκηνπξγνύκε έλα keyframe γηα ηελ «αξρηθή» θαηάζηαζε θαη έλα keyframe γηα ηελ «ηειηθή» θαηάζηαζε θαη νη ελδηάκεζεο θαηαζηάζεηο ππνινγίδνληαη απηόκαηα. 4
ΠΡΟΟΧΗ ΙΚ animations - Export animation από ην Maya Αλ ην animation ζαο ρξεζηκνπνηεί IK ηόηε πξηλ ην export θάλεηε ην αθόινπζν βήκα αιιηώο πξνρσξήζηε απεπζείαο ζην επόκελν. Bake the animation. In the Outliner select the Root bone. Then choose Edit>Keys>Bake Simulations (Options). In the Bake Simulation Options window, in Hierarchy click the Below radio button. In Time Range: click the Start/End option and for Start Time: enter 1 and for End Time: enter the last frame of all the animations you have. When everything is set, press the Bake button. Export from Maya MAYA Export as.fbx. Choose File>Export All Change the file type to FBX Export and (as we've done in the past) be sure that Embed Media is checked (in the Include section) 5
Import in Unity UNITY Σνπνζεηείζηε ην exported κνληέιν ζαο ζην Assets folder ηνπ project ζαο ζην Unity θαη αλνίμηε ην Unity. In the Project panel select the object prefab. This will show it in the Inspector panel. Import in Unity Change the Scale Factor to 1. Then look carefully (you may have to scroll down) to the Animation section and an area that has columns of Name, Start, End, WrapMode, and Loop. Click the little + symbol to tell Unity you wish to define/add an animation. As soon as this is done a new animation will appear already named idle. The Start column should read 1, but change the End entry to read e.g. 48. Change the WrapMode to Loop (not the Loop checkmark this is something else.) By changing the WrapMode to Loop, the animation will, well, loop until told to stop. If you have animated other animations, add them here now. When done, click the Apply button 6
Import in Unity name start frame stop frame WrapMode loop frame Defines the Animation Clip's name within Unity. The first frame of the animation. The frame number refers to the same frame as in the 3D program used to create the animation. The last frame of the animation. Defines how should time beyond the playback range of the clip be treated (Once, Loop, PingPong, ClampForever). If enabled, an extra loop frame is inserted at the end of the animation. This frame matches the first frame in the clip. Use this if you want to make a looping animation and the first & last frames don't match up exactly. Animate on request Γξάςηε ην πην θάησ script θαη θάληε ην attach κε ην αληηθείκελν ζαο function Update () { if (Input.GetKeyDown(KeyCode.LeftControl)){ rotateobjectonce(); function rotateobjectonce(){ animation.play("rotateanim"); yield WaitForSeconds(animation["rotateAnim"].length); animation.play("idle"); 7
2. built-in animation system ζηο Unity Γεκηνπξγία built-in animation ην Hierarchy panel, επηιέμηε ην αληηθείκελν ην νπνίν ζέιεηε λα θάλεηε animate. Choose Window>Animation. This will pull up the Animation window and timeline. (εκεηώζηε όηη κε ην Animation window, κπνξείηε λα δείηε (ζαλ readonly) θαη animations πνπ έρεηε θάλεη import) In the top-left corner is a little red dot (for record). Click this and a Create New Animation dialog box will appear. Enter nameofyouranimation.anim in the File Name input field and click Save. 8
Δμήγεζε γηα built-in animations Think of animations as components of GameObjects. Whenever an object is to be animated in Unity, Unity will create a separate editable file (with a.anim label) that will store the information. What this means is that the animation can be used again and again on other objects (which is powerful in itself ). It also means that there is this new asset that will be in the assets folder that is important not to delete. Note that after the.anim file is created, the Animation window will show the record button in the top left highlighted in red as if pressed. This is Unity's way of telling you that you can now record animations by creating and editing keyframes Play built-in animation Γηα λα πξνζζέζεηε έλα λέν θαηλνύξην animation παηείζηε ην Create New Clip Σα animations πνπ δεκηνπξγείηε κε ην built-in animation system ηνπ unity κπνξείηε λα ηα θαιείηε κε κώδικα με ακριβώς ηνλ ίδην ηξόπν όπσο θαη ηα animation πνπ θηηάμαηε κε ην Maya. 9
Play built-in animation function Update () { if (Input.GetKeyDown(KeyCode.LeftControl)){ moveobjectonce(); function moveobjectonce(){ animation.play("leftright"); yield waitforseconds(animation["leftright"].length); Γεληθά γηα animations Σα animations είηε ηα θηηάμαηε ζην Maya είηε ζην built in system ηνπ Unity, κπνξείηε λα ηα ρξεζηκνπνηήζεηε ζε νπνηνδήπνηε Game Object δεδνκέλνπ όηη έρεη Animation Component. Tα animations πνπ ζα ρξεζηκνπνηνύληαη πξέπεη λα είλαη elements ηνπ animation component Πξνζζήθε animation component. Δπηιέμηε ην αληηθείκελν Component Miscellaneous Animation 10
Γεληθά γηα animations Γηα λα πξνζζέζεηε έλα element ζην animation component απμήζηε ην size θαηά 1. Κάληε click ζην κηθξό θύθιν πνπ ζέιεηε λα πξνζζέζεηε θαη επηιέμεηε ην animation ηε ζπλέρεηα γξάςεηε script γηα λα θαιείηαη θάπνην animation λα παίδεη, θαη θάληε attach ην script ζην αληηθείκελν πνπ ζέιεηε λα έρεη ην ελ ιόγσ animation Γεληθά γηα animations Animation Component - Inspector Animation Animations Play Automatically The default animation that will be played when Play Automatically is enabled. A list of animations that can be accessed from scripts. Should the animation be played automatically when starting the game? Animate Physics Should the animation interact with physics. Animate Only If Visible When enabled, the currently playing animation will not play if the object is not visible on the screen. 11