• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

An object with multiple rockets? 1 Answer

Trigger-based vehicle ai? 1 Answer

Kinematic rigidbodies, colliders and performance 1 Answer

Building a Snap System, Need Help 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges