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 VicciGames · Jul 30, 2012 at 02:28 PM · animationphysicsraycasthitray

Playing an objects animation that has been hit by a RayCast


Problem: I want to play an objects animation that has been hit by the raycast


.

So basically I'm setting up a a desert arena where you have to hit the targets as fast as you can with select guns. Anyways, my current problem is where the player hits the target and it plays its animation to go down.

||I USE CSHARP MOST OF THE TIME, SO PLEASE NO JAVASCRIPT|| Thanks!

Here is what I have tried - SEND MESSAGE WITH RECEIVER.

I do have a theory that you could use a "spring" physics component on the object, so whenever there is a force acting upon it, it moves. But I decided to ask you all anyways, just for opinions.

Please help, ask for coding that is needed. But I believe this is all you need for now: Thank you all in advance!!



  void RayShoot (){
  
  
  if(!isReloading) {
  
  GameObject.Find("AK-47 FBX With Arms").GetComponent().Play("shoot");
  
  RaycastHit hit;
  
  //Vector3 DirectionRay = transform.TransformDirection(Vector3.forward);
  
  Vector3 direction  = transform.forward;
           direction.x += Random.Range(-spreadFactor, spreadFactor);
            direction.y += Random.Range(-spreadFactor, spreadFactor);
              direction.z += Random.Range(-spreadFactor, spreadFactor);
  
  
  Debug.DrawRay (transform.position, direction * Range, Color.blue);
  
  
  if(Physics.Raycast(transform.position, direction , out hit, Range)){
  
  SendMessage ("YourHit", true);
  
       if(hit.rigidbody){
  
  if(hitParticles){
  
  hitParticles.transform.position = hit.point; 
  hitParticles.transform.localRotation = Quaternion.FromToRotation(Vector3.forward, hit.normal);
  
  hitParticles.Emit();
  
  
  hit.rigidbody.AddForceAtPosition(direction * Force, hit.point);
  
  hit.collider.SendMessageUpwards("ApplyDamage", Damage , SendMessageOptions.DontRequireReceiver);
  
  }
  }
  }
  
  BulletsLeft--;
  
  if( BulletsLeft < 0){
  
  BulletsLeft = 0;
  
  }
  
  if(BulletsLeft == 0){
  
  Reload(); 
  
  }
  }
  }
Comment
Add comment · Show 2
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 Mr.Jwolf · Jul 30, 2012 at 03:22 PM 0
Share

I am a bit unsure what your problem is. Is it if you are doing it in a 'good way'? Or is something not working(like raycast never hits anything)?

avatar image VicciGames · Jul 30, 2012 at 04:01 PM 0
Share

$$anonymous$$y raycast hits and works perfectly fine, i just want to play an objects animation that has been hit by the raycast

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by Ingen · Jul 30, 2012 at 05:03 PM

Hallo. that's is what I use for what U want

sorry if is in JS I don't chew C# but is enough easy and short

  if( /*Input.GetButtonDown ("Fire1")*/  Input.GetKeyDown(KeyCode.R)) //input key
    {
          hit.collider.SendMessageUpwards("Active", SendMessageOptions.DontRequireReceiver);



"Active" is the message send, and function in second script need match and is case sensitive


and in the object who received the message

  var animatedObj1  : GameObject; // Dooor
  var animatedObj2 : GameObject; // Button
 
  function Active(){  
      animatedObj1.animation.Play();
              animatedObj2. animation.Play(); 
  }

hope can help

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

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

7 People are following this question.

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

Related Questions

Detaching a Physics Driven Object from a Character 2 Answers

Why in Unity3D RaycastHit. textureCoord always return 0,0 after building the project? 1 Answer

Animator and custom blended animation 0 Answers

Converting discrete intensity distribution to a continuous figure.,Discrete intensity to continuous figure. 0 Answers

Character Controller Component, Gravity/inertia, and Root Motion 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