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 zero6251 · Jun 19, 2015 at 06:39 PM · javascriptraycastcollider

How do I register damage from the actual sword? not Raycast

Hello I wish to create a small RPG with decent graphics and a cool story-line. But I have come across a road block. I wish to know how you can register damage when the sword hits a enemy not "look in a straight line and register damage before the animation is complete" due to raycast. If you have any way to update my original script to make this happen please tell me (Java Script)

 var TheDammage : int = 50;
 var Distance : float;
 var MaxDistance : float = 1.5; 
 
 function Update ()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         var hit : RaycastHit;
         if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
         {
             Distance = hit.distance;
             if (Distance < MaxDistance)
             {
             hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);`
 




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 AlwaysSunny · Jun 19, 2015 at 06:34 PM 0
Share

You can fire a ray from the hilt of the sword (whose length is the blade's length), or you can create a trigger which encompasses the blade. You'd only care about raycast hits or collisions during the attack animations.

avatar image zero6251 · Jun 22, 2015 at 06:01 PM 0
Share

Thank you for your input on the matter I an currently trying this out!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CelticKnight · Aug 17, 2017 at 01:10 AM

@AlwaysSunny

Sorry for the lateness on my reply, but, thankyou "AlwaysSunny" for pointing out that the collision needs to be a trigger. I was trying an OnCollisionEnter, which, of course, was not working the way I needed. You also correctly pointed out that the Trigger needed to be only generated during attack animations, due to the way the sword is attached to the characters hand I was getting triggers being generated when ever it got near another object.

This is the problem at hand, with triggers only being generated during an animation that is being generated by the Animator. Going to need some time trying to figure that out.

But thankyou greatly for that information. It has been very helpful!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Trouble with RayCast, rigid body and the colliders tag 0 Answers

Raycasting fail 1 Answer

If Raycast Hits Air 4 Answers

Bomberman like explosion 0 Answers

Accessing colliders, in if statement 2 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