Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
taichiu727

hit.characterController not working

Question

I want to to use hit.characterControler but it gives me this error 

 

 

MissingFieldException: UnityEngine.RaycastHit.characterController
Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.FindExtension (IEnumerable`1 candidates)
Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.Create (SetOrGet gos)
Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.CreateGetter ()
Boo.Lang.Runtime.RuntimeServices.DoCreatePropGetDispatcher (System.Object target, System.Type type, System.String name)
Boo.Lang.Runtime.RuntimeServices.CreatePropGetDispatcher (System.Object target, System.String name)
Boo.Lang.Runtime.RuntimeServices+<GetProperty>c__AnonStorey17.<>m__C ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name)
UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name)

 

Share this post


Link to post
Share on other sites

28 answers to this question

Recommended Posts


  • 0

A character controller is more than just a collider. That's why it's doesn't work. When a raycast hits a player, it's not hitting the character controller, it's hitting the controllers collider

Share this post


Link to post
Share on other sites
  • 0

I think you forgot the opening bracket after if (hit.rigidbody), and closing after send message.

It's actually much simpler than you are trying to do, just add a tag on Player "Player".

 

Please login or register to see this code.

Share this post


Link to post
Share on other sites
  • 0

To add on to YoungDeveloper, if you truly have to know if a character controller exists, you can get the component:

if(hit.gameObject.GetComponent(CharacterController))

{

print("hit a controller");

}

Share this post


Link to post
Share on other sites
  • 0

thx for helping but the problem is that somehow hit.collider doesn't seem to work for character controller, btw have to go sleep now i will check this tmr

Edited by taichiu727

Share this post


Link to post
Share on other sites
  • 0

Don't listen to them then, they are definitely wrong. hit.collider should return a character controller if it hits one, so I don't know what you're doing with the raycast but hit.collider should count character controller as a collider.

Share this post


Link to post
Share on other sites
  • 0

yeahi i know but i just don't know why it didn't work, i guess i would need to play around with it. and test more.. 

Share this post


Link to post
Share on other sites
  • 0

Stupid question, but how do you know you should be hitting the character controller, when I started with raycasts I had a lot of problems with it not working, only too realise that the ray was going backwards! Make sure it works with other things, and also there is a way too draw the ray in the editor window (I think it's Physics.DrawRay) or something similar

Share this post


Link to post
Share on other sites
  • 0

i don't know why but just doesn't work with character controller...!!! is there an alternate way? or how to get it work??

Share this post


Link to post
Share on other sites
  • 0

As stated a few times, character controllers are not just a collider. All a character controllers collider is a capsule collider which detects the same as any other collider.

Please login or register to see this link.

Please login or register to see this link.

They all state the same thing as we're saying

Share this post


Link to post
Share on other sites
  • 0

Just make sure your casting properly and either checking the hit objects tag or checking if the object has a character controller by getting the component and checking if it is not null

Share this post


Link to post
Share on other sites
  • 0

Debug the hit object's name: Debug.Log("Hit: " + hit.transform.name);

Then you would give the character controller a crazy name and see if it gets debugged. Also, you can do Debug.DrawLine(transform.position, hit.point, Color.red);

 

Can you please post the script one more time? (The current one)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...