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 oliver-jones · May 20, 2012 at 05:11 PM · rigidbodycollidercharactercontrollertranslate

Character - Collider With Scene

Hello,

I'm working on my own character controller, this is the first time I've ever done anything like this, so be easy with me.

I'm working on a simple top down game, where the character moves where the mouse is in the scene. I got all the movement working, thats all fine. What I'm trying to do now, is for the character to collider with objects in the scene.

So, I've added a collider to my player, and a rigidbody and turned off gravity (as I don't really need it in a top down, no jumping involved).

Now this works, I do collide, but then my character starts rolling, and rotating and moves backwards, out of control basically. So then I tried turning on some of the Constraints on the rotation, this works, my character doesn't lose control, but it seems like theres a force continually being applied against my character, causing him to move backwards.

Any ideas how I can have my character collider with the scene? Without losing control?

I'll attach my script and continue to look around, but I'm basically just using 'Translates'.

 function Update () {
     
     //makes direction arrow stay with character - on x and z axis only
     playerArrow.transform.position.x = transform.position.x;
     playerArrow.transform.position.z = transform.position.z;
 
     
 
     var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
     
     var hitdist = 0.0;
     //get the point along the ray that hits the calculated distance.
     var targetPoint = ray.GetPoint(hitdist);
 
     var lookPos = targetPoint - playerArrow.transform.position;
     lookPos.y = 0;
     var targetRotation = Quaternion.LookRotation(lookPos);
     playerArrow.transform.rotation = Quaternion.Slerp(playerArrow.transform.rotation, targetRotation, arrowRotateSpeed * Time.deltaTime);
 
 
     // ----- Move Character ----- \\
     
     if(Input.GetAxis("Vertical")){
         //rotate player to face direction arrow
         transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, playerRotateSpeed * Time.deltaTime);
         
         //them move player towards arrow direction
         var translation : float = Input.GetAxis("Vertical") * playerMoveSpeed;
         translation *= Time.deltaTime;
         
         transform.Translate(0,0,translation);
 
     }
     
     if(Input.GetAxis("Horizontal")){
         
         var panning : float = Input.GetAxis ("Horizontal") * playerMoveSpeed;
         panning *= Time.deltaTime;
         
         transform.Translate(panning,0,0);
 
         //pan the character left/right whilst looking at mouse position/direction arrow
         if(allowRotatePan){
             //rotate player to face arrow
             transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, playerRotateSpeed * Time.deltaTime);
         }
     }
 }
Comment
Add comment · Show 2
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 hijinxbassist · May 20, 2012 at 07:31 PM 0
Share

Have you read through Unitys Char Cntlr script? That would be the first place id start. See how they implemented it, and apply the same technique or modify it to fit your needs.

avatar image ExTheSea · May 22, 2012 at 03:56 PM 0
Share

The rolling around should come from the rigidbody. Try turning it off.

You could also use a character as it uses kinematics not using colliders. If nothing works you could give it a try.

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

messed up with character controller, collider and rigid body 0 Answers

Collision not working 1 Answer

Character Controller can pass through character controller after upgrade to 4.0 0 Answers

Moving Rigidbody with Translate causes vibrating player when walking into objects 2 Answers

Character Controller 2 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