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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by IKilledKenny_2 · Dec 17, 2014 at 12:34 AM · animationcollisiononcollisionenter

OnCollisionEnter Animation

Hello Unity3D.I have a question about OnCollisionEnter.Can i use OnCollisionEnter to force the enemy to play an animation without the enemy having any OnTriggerEnter script attached to it?The reason i ask this question is the fact that i am trying to make one of my characters be able to throw a enemy and i was wondering if i needed both parties to have a script or just one of them needs a script for this.If i only need a OnCollisionEnter script for me to be able to throw an opponent.Is this script correct then?

 #pragma strict
  var sceneCam : GameObject;
  sceneCam = GameObject.Find("MainCam");
 
 function OnCollisionEnter(collision : Collision){
 if(collision.gameObject.tag == "Dummy") {
 sceneCam.transform.position = Vector3(-20.46, 4.258904, -805.3136);
          if(animation.IsPlaying("punch1")){
                  animation.Play ("Hit1");
          }
      }
  }
  
Comment
Add comment · Show 4
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 richyrich · Dec 17, 2014 at 01:25 AM 0
Share

You only need the collision script to be on/attached to the GameObject that is perfor$$anonymous$$g the action as a result of the collision. You do however need colliders on both.

avatar image MajdHamada · Dec 17, 2014 at 01:41 AM 0
Share

If you wont to make enemy play animation without OnTriggerEnter() ......... this code help you .......

On your player script:

 var  enemy : GameObject
 
 
 function OnCollisionEnter(collision : Collision){
 
 if(collision.gameObject.tag == "Dummy") {
 
 sceneCam.transform.position = Vector3(-20.46, 4.258904, -805.3136);
 
 if(animation.IsPlaying("punch1")){
 
 enemy.animation.Play ("Hit1");
 
 }
 }
 }
avatar image Ericool · Dec 17, 2014 at 01:47 AM 0
Share

why not triggered? it is the best way for an animation

avatar image IKilledKenny_2 · Dec 17, 2014 at 04:08 AM 0
Share

I thought Collision Was better?..I got to stop watching those youtube videos....

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ericool · Dec 17, 2014 at 09:53 AM

For a collision or a collider you need something like a box collider and a rigidbody on the other gameObject. Careful, you want to play an animation so I suggest you to use OnTriggerEnter

Comment
Add comment · Show 1 · 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 IKilledKenny_2 · Dec 17, 2014 at 04:21 PM 0
Share

Now i gotcha.But wait ,OnTriggerEnter doesnt that have to be on the emeny ins$$anonymous$$d of the player?also how can i make it that he plays certain animations depending on what the player hit it with.For example i punch them the opponent covers his/her face.or i kick them the opponent goes twirling?

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

30 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Emit Particle on Collision Issue 0 Answers

Register collision between two specific game objects, using var (not tags or names). 1 Answer

Third Person: Picking up and carrying objects. 0 Answers

Collider on Bone changes Bone Origin/Pivot 1 Answer

How to stop an animation on collision 0 Answers


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