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 Joel 5 · Feb 28, 2011 at 05:25 PM · javascriptcharactercontrolleraddforcedamageattack

Punching - what would be the better way? (in javascript)

This is my first post. I made sure I search the related answers and the forums. I am trying to figure how to add damage to a rigidbody when it collides with my charactercontroller, so for my instance it would be punching. Before I go an corrupt my game by trying each way, I thought I would save time by asking for a second opinion.

One way I was told I could do it is by using AddForceExplosion on my character. But I was thinking that maybe I should make the radius of the capsule to my character a little wider and simply detect a collision.

What are your opinions on this?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by AngryOldMan · Feb 28, 2011 at 07:34 PM

on the rigidbody implement a life system by making a variable that get's life subtracted from it every time you punch it. then when life = 0 destroy game object. want anymore info on how just say.

Comment
Add comment · Show 2 · 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 Joel 5 · Mar 01, 2011 at 11:37 AM 0
Share

Thanks for the answer Bobadebob. I have already made a health system. What I am asking is how to get my character to punch an object and for it to be recognized the object has been hit. So I have my character and 1 unit gap between the character is an object i wish to hit. I am asking which option would be best in order to get a punching action working.

avatar image AngryOldMan · Mar 01, 2011 at 01:54 PM 0
Share

Ah i see, I think the method I would try (there may be a better way but Im sure that this would work) Would be to have a variable called something like "IsPunching" on your player which switches on automatically when your press punch and off when the punch animation is done.Then on the gameobject put a piece of script similar to this var PunchDamage : float = 10; var BoxLife : float = 20; Punched = PlayerPrefab.GetComponent(PlayerScript); if (Punched.Ispunching = true) { BoxLife = BoxLife - PunchDamage; }

avatar image
0

Answer by Joel 5 · Mar 01, 2011 at 01:41 PM

So I went for the simple option of just detecting the collision in the capsule of the character controller. If anyone comes across this question looking for how to do the task above. Set your character controller capsule width to the width slightly shorter of your punch animation and just run a OnControllerColliderHit function to detect the hit. Pretty simple, will post if I come along any major problems with this technique.

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

No one has followed this question yet.

Related Questions

I need help with my health script 2 Answers

Character controller mess up damage 3 Answers

Unknown Identifier "Other"... Character Movement Script 1 Answer

Stop Character Drifting after using AddForce 3 Answers

Change the gravity direction for CharacterController 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