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 UNKNOWN · Nov 28, 2012 at 01:49 PM · charactercontrolleraddforcetransform.positiontranslate

Character controller problem

First I tried to use Character controller but then I ran into problem with Character Collider which couldn’t be rotated or freely modified.

Then I used Transform.Translate tocontroll my 2D object but now it is going thru walls. I tried Rigid bodies, box colliders, mesh with convex but still nothing. Part of my script:

 var moveSpeed : double = 1.0;

 // Amount to move
 var amountToMovex =Input.GetAxis("Horizontal") * moveSpeed;
 var amountToMovey =Input.GetAxis("Vertical")   * moveSpeed;
 
 //Move the player
 currentShip.Translate(Vector3.right * amountToMovex);
 currentShip.Translate(Vector3.up    * amountToMovey);
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 Landern · Nov 28, 2012 at 02:21 PM 0
Share

Sooooooooooooooooooo, whats your question?

avatar image UNKNOWN · Nov 28, 2012 at 02:59 PM 0
Share

I want to be able move my character but when it hits the wall I want it to stop. Character controller would do that but Character controller has only capsule collider and my object is rectangle shape. I couldn't rotate that capsule collider. Half of my object goes through the wall before it hits the vertical capsule collider.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Paulius-Liekis · Nov 28, 2012 at 02:35 PM

Try putting forces on RigidBody instead of moving it with Transform.

Comment
Add comment · Show 4 · 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 UNKNOWN · Nov 28, 2012 at 05:32 PM 0
Share

I tried this but it doesn't work.

Does AddForce always have to be in FixedUpdate or can it be in Update

var amountTo$$anonymous$$ovex =Input.GetAxis("Horizontal") * moveSpeed;

var amountTo$$anonymous$$ovey =Input.GetAxis("Vertical") * moveSpeed;

//$$anonymous$$ove the player

currentShip.Rigidbody.AddForce(Vector3.right * amountTo$$anonymous$$ovex);

currentShip.Rigidbody.AddForce(Vector3.up * amountTo$$anonymous$$ovey);

avatar image DecipherOne · Nov 28, 2012 at 10:56 PM 0
Share

There are a number of possible reasons this isn't working for you. Some things to look for, make sure you have a big enough collider on your rigidbody, as well as making sure that you have static colliders applied to what ever makes up your wall that you are trying to collide with.

avatar image kag359six · Nov 28, 2012 at 11:40 PM 0
Share

You misunderstood Paulius. If you are using forces, you can't use a CharacterController too. And the player has to have a Rigidbody attached to it, you can't just call the Rigidbody class on the ship if it doesn't have a rigidbody.

avatar image UNKNOWN · Nov 29, 2012 at 01:00 PM 0
Share

The character controller works great but I can't modify hard coded capsule collider that is attached to it.

I tried to search but there's not perfect answer to my problem. I will have to work on sollution now.

Thank you for help everybody.

avatar image
0

Answer by kag359six · Nov 28, 2012 at 11:39 PM

You can use a character controller. it handles the collisions for you. just create:

     var controller = GetComponent("CharacterController");
     
     var moveX = Input.GetAxis("Horizontal") * speed;
     
     var direction = new Vector3(moveX, moveY, 0);
     
     controller.Move(direction * Time.deltaTime);

Go to this link here for a full example of using the controller.

Comment
Add comment · Show 1 · 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 UNKNOWN · Nov 29, 2012 at 12:46 PM 0
Share

I see that I can't have Character controller atached to other object.

I had my Transform.Translate script attached to empty object which had DontDestroyOnLoad and I was able to swap between controlling different objects.

Now I will have to come up with different sollution for that.

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

14 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

Related Questions

Use force instead of transform.position 1 Answer

Drawbacks of Moving Rigidbody by transform.translate 1 Answer

AddForce on diagonals C# 1 Answer

Forward or Reverse Character Position Skateboard Game 0 Answers

Stop Character Drifting after using AddForce 3 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