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 IAmJeff · Nov 20, 2013 at 04:41 AM · colliderscharacter motordebug.drawline

help on several mechanics

I'm creating a game and I'm encountering several issues. None are errors, but they aren't functioning the way I want them too.

  1. I have a crouching, walking and sprinting mechanic. When I walk or sprint the character motor updates properly. However, when I crouch, the character motor doesn't update despite using the same code (just using different values).

  2. I'm using a debug.drawray so I can see a visual representation of what the enemy sees. However, whenever the enemy rotates, the line doesn't line-up properly with the z-axis.

    Vector3 losLeft = transform.TransformDirection(Quaternion.Euler(0, -fieldOfViewRange, 0) * transform.forward).normalized * drawLine;

    Vector3 losRight = transform.TransformDirection(Quaternion.Euler(0, fieldOfViewRange, 0) * transform.forward).normalized * drawLine;

    Debug.DrawRay(transform.position, losLeft, Color.green); Debug.DrawRay(transform.position, losRight, Color.green);

  3. I have a crossbow and when it fires, it doesn't get stuck to a wall. Both the arrow and the wall have a collider. The bolt has a tag and I enable kinematic, translate it forward and then parent it to the object it hits.

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
0

Answer by Bunny83 · Nov 20, 2013 at 04:54 AM

What should we do about No 1?

No 2 is quite simple ;) You used TransformDirection but don't passed in a local direction but the worldspace direction. This would result in a double rotation. So either use TransformDirection and Vector3.forward instead of transform.forward, or just remove the TransformDirection.

ps: "drawLine" is the perfect example of a misnamed variable ;)

No 3 is almost like No 1 however slightly more information here. How do you "translate" the arrow? With "Translate()"? That would bypass the physics system and you don't get any collisions. Just attach a Rigidbody, set drag to 0, disable gravity and set the initial velocity (either directly or by using AddForce).

Comment
Add comment · Show 6 · 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 IAmJeff · Nov 20, 2013 at 05:46 AM 0
Share

Thanks #2 is solved. However, still having an issue with #3. Does both the arrow and the wall need a rigidbody or only one of them? I've applied it both and disabled gravity and drag is set a zero.

Here's the code, maybe I'm missing something:

     void OnCollisionEnter(Collision hit)
     {
         float depth = 0.3f;
         
         if(hit.transform.tag == "Bolt")
         {
             hit.rigidbody.is$$anonymous$$inematic = true; //stop physics
             //hit.transform.Translate(depth * Vector3.forward); //arrow peneration (took it out like you said)
             hit.transform.parent = transform; //attach it to the enemy
         }
     }
avatar image robertbu · Nov 20, 2013 at 05:52 AM 0
Share

This answer might help you with #3:

http://answers.unity3d.com/questions/462907/how-do-i-stop-a-projectile-cold-when-colliding-wit.html

avatar image IAmJeff · Nov 20, 2013 at 06:15 AM 0
Share

Still no luck despite. Despite trying both methods =S.

avatar image Bunny83 · Nov 20, 2013 at 11:33 AM 0
Share

$$anonymous$$aybe you want to share your "issue with #3" with us? What exactly happens? Does the arrow move? Does it stop at the target? If so, what's your actual problem...

The people here are quite good at guessing what people want to ask, but out of thin air there's not much we can do ;)

avatar image Bunny83 · Nov 20, 2013 at 11:41 AM 0
Share

BTW, is the script you posted above on your arrow / bolt? If so it doesn't make much sense to check the object it hit for the tag "bolt". That would make it work only when hitting another bolt. Unless your name is Robin Hood that's a quite rare case :P

To answer you question in the comment above:
Only the moving object (probably the bolt / arrow) needs a Rigid body. However both objects need a collider, the bolt as well as the wall you want to hit.

Show more comments

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

18 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

Related Questions

physics.OverlapSphere colliders 1 Answer

I need help with Trigger collision detecting tags 0 Answers

Runner game collider 1 Answer

Ragdoll and Animator Collisions, 0 Answers

Is there a way to increase the max number of colliders in the ParticleSystem.trigger module? 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