Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 07, 2013 at 08:26 PM by Fattie for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by puzzledragon · Jul 18, 2011 at 01:27 PM · meleefirst-personsword

First person sword fighting

There doesn't seem to be a step by step tutorial on this can you show me one?

My problem is that I can get my character to hold the sword, but I cant figure out how to make him slash and do damage while still getting the movement controls to work correctly this is the script im using:

 var swordPoints : Transform[];
 var swingPower : int;
 var showGizmosInEditor : boolean = false;
 
 
 function Update () 
 {
     var hit : RaycastHit;
     for(i = 0; i < swordPoints.length; i++)
     {
         if(Physics.Linecast(transform.position, swordPoints[i].position, hit))
         {
             Hit(swordPoints[i], hit);
         }
     }
 }


 function Hit(i : Transform, hit : RaycastHit)
 {
     if(hit.collider.rigidbody)
     {
         hit.collider.rigidbody.AddExplosionForce(swingPower, i.transform.position, 1.0, 3.0);
     }
     if(hit.collider.tag == "Enemy")
     {
         hit.collider.gameObject.SendMessageUpwards("ApplyDamage", swingPower, SendMessageOptions.DontRequireReceiver);
     }
 }


 function OnDrawGizmosSelected()
 {
     Gizmos.color = Color.blue;
     if(showGizmosInEditor)
     {
         if(swordPoints.length != 0)
         {
             for(i = 0; i < swordPoints.length; i++)
             {
                 if(swordPoints[i] != null)
                 {
                     Gizmos.DrawLine(transform.position, swordPoints[i].position);
                 }
             }
         }
     }
 }
Comment
Add comment · Show 8
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 BerggreenDK · Jul 18, 2011 at 02:08 PM 1
Share

I've reformatted your code a bit to make it more readable (remember to mark code in the text with the 010101-button next time). Unfortunately, that didnt help me understand where your problem is in the code? can you explain it a little more?

avatar image puzzledragon · Jul 18, 2011 at 02:22 PM 0
Share

I got this script from google my problem is that it doesn't seem to take effect when I try to add it as a component it removes my char motor thank you for helping with the script though

avatar image Chris D · Jul 18, 2011 at 03:51 PM 3
Share

Start with a tutorial. Using random code you've found is just going to give you headaches and won't $$anonymous$$ch you a single thing about the scripting you'll need to actually make games.

avatar image BerggreenDK · Jul 18, 2011 at 09:20 PM 1
Share

I dont think I have removed/changed your code @puzzledragon I merly formatted it for viewing purpose. I agree with @ChrisD - perhaps you should think of starting with something a little easier and then work your way up through tutorials. Scripting is like writing a book, you need to learn your ABC first.

avatar image Bobtheblacksmith · Apr 07, 2013 at 08:25 PM 1
Share

Don't do it through scripting do it through animation

Show more comments

1 Reply

  • Sort: 
avatar image
4
Best Answer

Answer by JUnityer · Jul 21, 2011 at 11:38 AM

Agree with the commenters, start by learning analyzing code, and don't just pick other's scripts from the internet and expect that they work immediately! :)

But I'm going to give you a little help anyway:

Make a script for your sword or add stuff to your movement script. Check if the user presses a button (mouse1 for example), and then make the sword swing using an animation. Then check if there is collision between the sword and the object you want to kill.

Search the scripting reference for all these functions.

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

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

Swinging a sword through code 3 Answers

Best way to detect sword hit 0 Answers

RPG Swing attack hit detection 6 Answers

on collision damage 1 Answer

What is the best way to do third person melee combat? 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