Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Guille_b · Jun 17, 2015 at 07:22 PM · animationenemyballautomaticthrow

Create an Enemy Animation

Hi!

I´m new in Unity. I'm trying ti create an Enemy which can throw a ball to an object. I created tow animations for that. One is the "waiting" animation that is a loop and repeats over and over again. Between this loop there is a "fire" animation which the Enemy Throw a ball to this object. The enemy have to spawn the ball in the hand of it every time it was thrown...

Probably because I'm new it is hard...

Can someone help me?

Thanks!!

PD: Sorry for my english...

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Nik-60 · Jun 23, 2015 at 12:48 PM

First of all declare two variables, A Gameobject and a Rigidbody

     private GameObject Projectile_Spawn;
     public Rigidbody Projectile;

Under the start function find the object hand of your enemy

     Projectile_Spawn = GameObject.Find ("Hand");

And finally within the enemy condition start a coroutine

     StartCoroutine (ShootProjectiles);

And finally the Coroutine

         IEnumerator ShootProjectiles() {
         Anim.Play ("Your_Shoot_Animation");
         Rigidbody shot = Instantiate (Projectile, Projectile_Spawn.transform.position, Projectile_Spawn.transform.rotation) as Rigidbody;
         shot.velocity = transform.TransformDirection (Vector3.forward * 5);
         }

Also check the Unity Scripting API

There are tons of example code's in both C# and Java. Happy learning...

Regards,Nik-60

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Cherno · Jun 22, 2015 at 04:24 PM

Hello,

the first stop for finding out how things work should always be the Unity Scripting API and the Unity User Manual. To make your enemy throw the object, you need to know about three things: 1. The animations (which you already have), and how to play them (this differs depending on wether you use the old Animation component, or the newer Animator component). 2. A prefab of an object that will be spawned in the hand, and the Instantiate function to make a copy of this prefab in the game world 3. A script on the object to make it move towards the target position. Vector3.Lerp or Transform.Translate would be simple solutions, but for realistic behavior you might want to give the ball or whatever a RigidBody and use the AddForce function when it is thrown.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MegaChuck64 · Jun 22, 2015 at 08:51 PM 0
Share

are your animations imported from another program?

avatar image Guille_b · Jun 23, 2015 at 01:03 PM 0
Share

Yes, the animation comes from $$anonymous$$aya...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Joints & Throws 1 Answer

Can I make animations snap to a frame? 1 Answer

Enemy offset, gallaga style game (space invaders) 0 Answers

How to make an enemy pace? 1 Answer

Animation made in blender does not loop 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges