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 Seth-Bergman · Feb 16, 2012 at 09:50 AM · movementraycastdistancephysics.raycastmomentum

Raycast distance affected by momentum of character

Hello all,

basically I'm working on a fighting game, and I'm using a raycast from the player position forward at given punch distance to test for a hit. I'm using controller.SimpleMove for movement. Everything seems to work right if I'm standing still, but if I'm walking toward the other character, punches will land from far, far away (and even then the hit.distance is extremely low). Here's the relevant code:

 function ApplyPunch(punchType : punch)
 {
 var hit : RaycastHit;
 var fwd = transform.TransformDirection (Vector3.forward);
 var pos = transform.position;
 var distance = punchType.distance;
 
 if (Physics.Raycast (pos, fwd, hit, distance)) {
 
 etc....

If I'm standing right in front of the other guy, hit.distance is about .5, but if I'm moving toward him, even from all the way across the scene, it's about .02. So I guess the question is, how can I get my raycast to ignore the momentum of my character? None of the variables being passed in (as shown above) change when I'm moving, so I just can't figure out why this is happening. Thanks in advance to anyone with suggestions..

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

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by goranzoricic · Feb 16, 2012 at 10:45 AM

Are you sure that your ray cast is hitting the other guy, and not the character that is shooting it? Such a short distance would suggest something like that. You should make sure that the ray cast ignores the originating character. Perhaps something like this:

http://forum.unity3d.com/threads/37900-Raycast-quot-Ignore-quot-Layers

Comment
Add comment · Show 3 · 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 Owen-Reynolds · Feb 16, 2012 at 06:42 PM 1
Share

Try adding (inside the if(raycast)) Debug.Log(hit.transform.name) or tossing in a Debug.DrawRay to show the raycast.

Raycasts don't use momentum. Something else about movement is messing you up -- maybe running angles your head forward, so the old raycast came from inside your head (so ignored it) and the new one hits the back of your own head.

avatar image Seth-Bergman · Feb 16, 2012 at 11:49 PM 0
Share

Hmm, yep, thanks to you both, can't believe I missed that. I'm using if(hit.collider.gameObject == otherplayer), to double-check, but I had a bracket in the wrong place, so it was only checking on blocked punches... $$anonymous$$oved the bracket to include hits, problem solved. Thanks!

avatar image Seth-Bergman · Feb 17, 2012 at 12:28 AM 0
Share

Now if only I could figure out how to accept your answer on this page...

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

Unreliability of Physics.Raycast.Distance for player movement? 0 Answers

Raycasts left/right problem. One works, other doesn't...? 1 Answer

How to get the distance between two objects in feet/meter? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Slant Physics Raycast Implementation 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