• 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
Question by ExyloN · Jul 13, 2012 at 02:35 PM · charactermousecolliders

Mouse Controlled Character and Colliders

Hi, im having some problems with my mouse controlled character, its going through buildings even when they have colliders. I've tried all the colliders and none prevent the character from going through. I was able to find a work around by adding a rigid body on the character and freezing position on X and Y, and freezing rotation on X, Y and Z. This way the character doesnt go through buildings but whenever I click on the position I want him to go he keeps sliding (because I didnt freeze position on Z). Any solution for my problem?

Heres a screenshot of the problem:

http://img534.imageshack.us/img534/5138/colliders.jpg

Regards, ExyloN

Comment

People who like this

0 Show 3
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 Piflik · Jul 13, 2012 at 02:46 PM 1
Share

Not sure if this is a mistake, or you advertising for that website, but the link doesn't lead to a screenshot, but the frontpage.

avatar image ExyloN · Jul 13, 2012 at 02:52 PM 0
Share

it was a mistake im fixing it now

avatar image ExyloN · Jul 13, 2012 at 02:56 PM 0
Share

This is the code that im using:

 //variaveis
 var vel : int;
 vel = 0;
 var Animacao : Animation;
 //Clipes de animação
 var clipes:AnimationClip[];
 //Guarda se ja foi clicado
 private var clicado:boolean = false;
 private var seta : GameObject;
 
 function Start()
 {
     seta = GameObject.CreatePrimitive(PrimitiveType.Plane);
     seta.transform.position = Vector3(0, 0, 0);
 }
 
 function Update()
 {
     //se clicou com botão esq
     if(Input.GetKeyDown(KeyCode.Mouse1))
     {
         //Cria um plano com a posição da personagem
         var playerPlane = new Plane(Vector3.up, transform.position);
         
         //Desenha um ponto entre o personagem e o local clicado
         var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         var hitdist = 0.0;
         vel = 10;
         
         //Seta que foi clicado
         clicado = true;
         
         //Verifica se pode mover-se e desenha o caminho
         if (playerPlane.Raycast (ray, hitdist))
         {
             //cria variavel depois de criado o caminho
             var targetPoint = ray.GetPoint(hitdist);
             
             //guarda a rotação
             targetPosition = ray.GetPoint(hitdist);
             
             var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
             seta.transform.position = Vector3(targetPosition.x,targetPosition.y,targetPosition.z );
             
             //Ajusta rotação da personagem
             transform.rotation = targetRotation;
         }
     }
     
     //Caso a personagem não esteja no ponto clicado ela anda até lá
     if((transform.position - seta.transform.position).magnitude > 2)
     {
         transform.Translate(Vector3.forward * ( Time.deltaTime * vel));
         
         //animação dele a andar
         Animacao.clip = clipes[1];
         Animacao.Play();
     }
     else
     {
         //animação dele parado
         Animacao.clip = clipes[0];
         Animacao.Play();
     }
 }

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Piflik · Jul 13, 2012 at 02:49 PM

How are you moving the character? Things like 'transform.position' or 'transform.Translate()' ignore all colliders. If you want to have collisions between player and scenery, you need to use the rigidbody to move the object (e.g. rigidbody.AddForce() or rigidbody.velocity).

Comment
Sup3rpanda

People who like this

1 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why does my character fall through the floor if I put colliders on his feet and not the body? 1 Answer

Getting 2 colliders, prefab and clone need help please. 0 Answers

Multiple colliders on one game object 1 Answer

Multiple Colliders On A Single Object Detecting Each Collider In OnTriggerEnter() 1 Answer

how to properly setup a character [closed] 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