-
Notifications
You must be signed in to change notification settings - Fork 11
Animation Tutorial
This builds upon an existing animation tutorial. https://www.raywenderlich.com/1494-introduction-to-unity-animation
The first thing we have to do is set up our scene to match the start of the scene in the existing tutorial except we will be building off of our YUXI examples.
So to start open up the YUXI example project and open the "BaseBoaARd_BaseScene"
Before we go any further please resave the scene as "Animation Tutorial"
We need to change the scale of the objects in the scene so the physics act better and so our imported objects are closer to real world scale. So select the object BaseBoARd and change the scale to 1,1,1
Now we need to rotate the scene so that gravity will be down when we hold the paper up to the camera so again select BaseboARd and rotate it to 270,0,0
We don't need the models of the raspberry pi and some of the other things that come in the scene so lets disable them in the Inspector window by unchecking the top box of [Breadboard, Raspberrry Pi, and Billboard_Poly_byGoogle.
The next thing i found useful was to create a new box I names paper box, to be the base of the paper you are holding. I made it. 3, 1.3, 01 and position it at -.9,0,0
Download the package from dropbox and save it where you can find it on your computer. https://www.dropbox.com/s/pi0mquxq3pmou9t/ClownExport.unitypackage?dl=0
Go to Assets -> Import Package -> Custom Package and find where you downloaded the package to.
make a new script in the Main Camera object and call it CakeFromCamera
using UnityEngine;
using System.Collections;
public class CakeFromCamera : MonoBehaviour
{
float timeOfLastThrow;
public GameObject cakePrefab;
public float throwingDelay = 0.5f;
public float yImpulse;
public float zImpulse;
public float xImpulse;
GameObject cake;
GameObject cakeStart;
// Use this for initialization
void Start()
{
timeOfLastThrow = Time.time - throwingDelay;
cakeStart = GameObject.Find("Main Camera");
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonUp(0) && Time.time - timeOfLastThrow > throwingDelay)
{
timeOfLastThrow = Time.time;
Vector3 startPos;
Quaternion startRotation;
startPos = cakeStart.transform.position;
startRotation = cakeStart.transform.rotation;
cake = Instantiate(cakePrefab, startPos, startRotation);
Rigidbody cakeBody = cake.GetComponent<Rigidbody>();
cakeBody.AddForce(transform.forward * xImpulse);
cakeBody.AddForce(transform.up * yImpulse);
}
}
}
after making the script. drag the cakePrefab from the prefab folder onto the cake prefrab object variable on the script then set the z impluse to 300 and the x impluse to 1200
if it works you should be able to hold up the paper and click in the game window and it will launch cakes at the paper and bounce off of it.
at this point you can switch to the public tutorial. https://www.raywenderlich.com/1494-introduction-to-unity-animation