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 drodrii · May 30, 2014 at 05:00 PM · 2drigidbodycharactercontroller

Preventing Movement - Character Controller - 2D

Hello everybody,

So I want my character to NOT move when stumbling upon rigidObjects, I've attached character controller to my player and added a boulder Object.

I had my character have rigid body && box collider but I was told character controller might be more suitable when using the player.

But when I "collide" with objects it keeps moving, what am I missing?

The setup is as follows:

Player: has character controller attached and when it moves it moves as follows":

When up button is pressed:

 transform.Translate (Vector3.up * speed * Time.deltaTime);


Boulder Object is as follows"

Rigidbody2D && box Collider2d attached....

Thanks for your time and help!

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 PouletFrit · May 30, 2014 at 05:10 PM

You shouldn't move gameobject that have a rigidbody or a character controller with translate. Translate will "teleport" your gameobject right to the position, and thus not detecting collision. Use rigidbody.MovePosition for gameobject with rigidbody or SimpleMove or Move with character controller.

 public float speed = 3.0F;
 public float rotateSpeed = 3.0F;

     void Update() {
         CharacterController controller = GetComponent<CharacterController>();
         transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);
         Vector3 forward = transform.TransformDirection(Vector3.forward);
         float curSpeed = speed * Input.GetAxis("Vertical");
         controller.SimpleMove(forward * curSpeed);
     }

Take a look at Character Controller Unity API

Comment
Add comment · Show 5 · 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 drodrii · May 30, 2014 at 05:18 PM 0
Share

@PouletFrit

So Imagine I created a button in the HUD. $$anonymous$$y character ain't moving.

There's no "rotating" with my character.

You either move Y+ or Y-, X+ or X-....

Here's an example with your code of moving along the Y+ axis.

 if (gui.upClicked == true) {
 
                                 
                 
                                 forward = transform.TransformDirection(Vector3.up);
 
                                 Debug.Log (forward);
                                 _controller.Simple$$anonymous$$ove(forward * speed * Time.deltaTime);
                                 
 
                                 //Clamps the position, so if the user goes beyond $$anonymous$$ or max he won't move.
                                 tempPosition = transform.position;
                                 tempPosition.y = $$anonymous$$athf.Clamp (tempPosition.y, $$anonymous$$Y, maxY);
                                 tempPosition.x = $$anonymous$$athf.Clamp (tempPosition.x, $$anonymous$$X, maxX);
                                 transform.position = tempPosition;
             
             
             
             
                                 gui.upClicked = false;
             
                         }
avatar image PouletFrit · May 30, 2014 at 05:37 PM 0
Share

what is your question?

avatar image drodrii · May 30, 2014 at 06:21 PM 0
Share

@PouletFrit

Well....the player ain't moving. What am I missing? Sorry

avatar image PouletFrit · May 30, 2014 at 07:01 PM 0
Share

I think for Simple$$anonymous$$ove to work, your gameObject would need to be considered grounded, so I'm not sure that you should use it.

Depends on what kind of game you want to make, but I think that rigidbody2D and a Collider2D would be more appropriate in your case.

 void OnGUI() {
     if (GUI.Button(new Rect(10,10,50,20), "Up") {
         rigidbody.$$anonymous$$ovePosition(Vector3.up * speed * Time.deltaTime);
 
         tempPosition = transform.position;
         tempPosition.y = $$anonymous$$athf.Clamp (tempPosition.y, $$anonymous$$Y, maxY);
         tempPosition.x = $$anonymous$$athf.Clamp (tempPosition.x, $$anonymous$$X, maxX);
         transform.position = tempPosition;
     }
 }
avatar image drodrii · May 31, 2014 at 02:16 PM 0
Share

@PouletFrit

The camera is almost identical to that of Pokemon Gameboy. As I stated the game is 2D so Im using RigidBody2D....Simple move won't work :(

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

21 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 avatar image avatar image avatar image

Related Questions

Unity 4.3 CharacterController collision with physics 2D not working 1 Answer

CharacterController or Collider/Rigidbody 2 Answers

2D rigidbody movement & walls 2 Answers

2D Collision Between Sprites 0 Answers

How would I make a route that shows where player moves beforehand? 0 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