HNRS 304.503 Lecture 16 – A boat, fixed coin spin-up, water, and a message box
November 14, 2012 by Chris Johnson. Filed under fall 2012, honors 304.503, lectures.
Agenda
- Your models
- Character Controller
- Fixing animation from last time
- Span animation window across all actions
- Parent a model with an empty, position the empty
- Modeling a boat in 5 minutes
- Adding water
- Using GUI.Box for messages
- Themes
Modeling a boat
- Make a long, thin rectangular prism.
- Select the top and bottom faces.
- Subdivide with some odd number of cuts.
- Select all prow faces.
- Turn on proportional editing, sharp mode.
- Scale inward to 0 (sx0, if on the x-axis), mouse-wheeling to change the sphere of influence.
- Remove doubles.
- Select all stern faces.
- Scale inward, but not to 0.
- Loop cut and slide all three sides to make a foundation for the walls.
- Extrude up.
- Scale out.
- Select the two vertices on the bottom of the prow.
- Merge.
- Raise the bottom of the prow up.
- Add two seats.
- Scale front and back faces independently.
Water
- Create terrain.
- Import Water package.
- Drag water into project.
- Scale.
Meet Boat
- Place boat.
- Add an empty on the shore near the boat.
- Give it a sphere collider.
- Make collider a trigger.
- Add a script:
private bool isNearBoat;
private GameObject player;
public GUISkin skin;
void Start() {
player = GameObject.Find("Player");
}
void OnGUI() {
if (isNearBoat && !player.GetComponent<CharacterMotor>().jumping.enabled) {
GUI.Box(new Rect(10, Screen.height - 70, Screen.width - 20, 60), "You're too heavy laden to board the boat.", skin.box));
}
}
void OnTriggerEnter(Collider collider) {
isNearBoat = true;
}
void OnTriggerExit(Collider collider) {
isNearBoat = false;
}
- Add GUI Skin in project panel.
- Increase box font size.
- Add script to empty.
Flip-up coins
- Add an empty where you want a coin to appear.
- Add a coin as a child object.
- Add a collider to the empty.
- Make the collider a trigger.
- Add a script to the empty, which will need to access it’s child object:
private Transform coin;
private bool isHit;
private GameObject player;
void Start() {
coin = transform.Find("greedee_coin");
isHit = false;
player = GameObject.Find("Player");
}
void Update() {
if (isHit) {
// keep the coin in view
transform.position = player.transform.position + 2.0f * player.transform.forward;
}
}
void OnTriggerEnter(Collider collider) {
if (!coin.animation.IsPlaying("dissipate")) {
isHit = true;
coin.animation.Play("dissipate");
Destroy(gameObject, 2.0f);
player.GetComponent<CharacterMotor>().jumping.enabled = false;
}
}
Haiku
“Three wishes I’ll grant”
The third is three more wishes
Or 3-d printer
show