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 question was closed Apr 21, 2016 at 10:40 PM by Akabuu for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Akabuu · May 21, 2014 at 07:59 PM · animationphysicscollideranimation controllersword

How do i make a sword that pushes other objects when it hits, using animations.

I have a character with attack animations and i want the other objects to be affected by it when i swing the sword. I tried collision boxes and what not and it seems the collision box doesn't follow the sword during the animation, it just stays in place. So i guess im trying to find a way to apply the animation to the collision box.

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

1 Reply

  • Sort: 
avatar image
0

Answer by tw1st3d · May 21, 2014 at 08:29 PM

So, this is what I came up with.

 using UnityEngine;
 using System.Collections;
 
 public class RotateOnHit : MonoBehavior
 {
     private bool rotate = false;
     private float triggered = 0.0f, currentTime, timer;
     
     public void Start()
     {
         this.timer = 10.0f;
     }
     
     public void Update()
     {
         if(this.rotate) {
         
             if(this.triggered == 0.0f) {
                 this.triggered = Time.deltaTime;
             }
             
             this.currentTime = Time.deltaTime;
             
             if((this.currentTime - this.triggered) < timer) {
                 // Should perform a relative spin
                 transform.Rotate(Vector3.right * Time.deltaTime, Space.World);
             } else {
                 this.rotate = false;
             }
         }
     }
     
     // This may not be the correct method name pretty sure it is though
     public void OnCollisionEnter(Collider e)
     {
         if(e typeof GameObject) {
             // I haven't worked with Unity in a while,
             // So it may be a different object path
             if(e.gameObject.tag == "sword") {
                 this.rotate = true;
             }
         }
     }
 }
Comment
Add comment · Show 4 · 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 Akabuu · May 22, 2014 at 04:35 PM 0
Share

sorry, i don't know C# very well, can you explain what it's suppose to do? also, i figured out that the collider doesn't move along because the sword itself doesn't change place, the mesh renderer is what makes it look like it does.. any alternative ideas to replicate the push of the sword?

avatar image tw1st3d · May 23, 2014 at 02:43 PM 0
Share

Create an animation that moved the characters arm(or the sword), causing the sword to swing and hit the target. On contact, OnCollisionEnter() will fire. Perhaps create a velocity algorithm to create a faux jump system?

Also, what this script does, is listens for a collider hit, and then moves the object for 10 seconds by Time.deltaTime on the Vector3.Right plane.

avatar image Akabuu · May 23, 2014 at 07:49 PM 0
Share

the problem is that i already have an animation. i dont think i can apply an animation to the mesh collider itself unless the sword is moving with some kind of physics based animation

avatar image tw1st3d · May 24, 2014 at 12:02 AM 0
Share

You are incorrect. Give the sword a thin box collider and listen for the event.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Physics.ignoreCollision and Animations: Not playing nicely together 1 Answer

Colliders run slower on animated objects? 1 Answer

Collision occurring when it should not! Help! 1 Answer

Can you gradually slow an fbx animation on raycast hit, then speed it up again after a certain amount of time? 1 Answer

Physics dont take place until animation is done? 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