Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Procedural Content Generation for Unity Game Development

You're reading from   Procedural Content Generation for Unity Game Development Harness the power of procedural content generation to design unique games with Unity

Arrow left icon
Product type Paperback
Published in Jan 2016
Publisher
ISBN-13 9781785287473
Length 260 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ryan Watkins Ryan Watkins
Author Profile Icon Ryan Watkins
Ryan Watkins
Arrow right icon
View More author details
Toc

Adding scripted weapon animation


The art we imported for our weapon modules is static, which means that we didn't add in any supplemental art to create animations. If we had added in these animations, our art assets would have increased dramatically, and we are trying to avoid this. So, instead, we are going to do what we have been doing and rely on programming.

We want the randomly constructed weapon to animate a swing when the player attacks. So, we are going to program the animation in such a way that it is the same for all the Weapons. This process is very much based on experimentation to get the right look and feel. One solution can be seen in Code Snip 6.8. The code is in the Weapon class definition as the Update function definition:

1 void Update () {
2   if (inPlayerInventory) {
3     transform.position = player.transform.position;
4     if (weaponUsed == true) {
5       float degreeY = 0, degreeZ = -90f, degreeZMax = 275f;
6       Vector3 returnVecter = Vector3.zero;
7
8       transform...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime