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
1
Question by Hor · Jun 22, 2012 at 11:14 PM · movementrigidbodycharactercontrollergravitysphere

Sphere + rigidbody + character controller

PS: Im super noob, started yesterday ;(

I read so many things about it, and no one could help me.

Im trying to simple add gravity to an object, AND movement too. I can't do it just adding rigidbody (because of gravity) and Character Controller (because of movement) i don't know, this things just dont stack!

Anyone can help me? I really need to move an object WITH gravity acting on it.

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
3
Best Answer

Answer by aldonaletto · Jun 22, 2012 at 11:52 PM

The CharacterController is what you need. If you just want gravity, move it with SimpleMove(speed) - speed is the velocity vector that shows in which horizontal direction to move. speed.y is ignored: SimpleMove takes care of the gravity for you. This is great, but as a bad collateral effect you can't add code to jump (vertical movements are totally under system control). The example script in SimpleMove is all you need to move your character in the old Doom style: AD rotates the character, and WS moves it forward/backward.
If you plan to control vertical movement - to add things like jumping or flying, for instance - use Move(offset) instead (offset is the absolute displacement that the character will move). It's more complex, since you must provide the gravity code. The example in Move provides gravity and jump code, and moves the character to left/rigth/forth/back with the keys ADWS.
These examples work fine (the FPS Tutorial player movement script is basically the Move example, and the enemies are moved with SimpleMove) and are a good starting point to add other features.

NOTE: The only unsolvable problem with the CharacterController is the vertical direction: it's assumed to be the Y axis, and you can't change this (to make the character walk on the walls, for instance).

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 Hor · Jun 23, 2012 at 12:07 AM 0
Share

First of all, thanks a lot! Im reading and trying to apply youur tips. $$anonymous$$y first question is: when a window popup telling that "The sphere collider is already added", should i replace, or just add? There two things will stack or just be a trouble for me?

avatar image Hor · Jun 23, 2012 at 12:11 AM 0
Share

I guess its a good thing to say that i have a 2D game, i just want to move a ball to left and right, and make him fall if have any hole on the way.

avatar image Bunny83 · Jun 23, 2012 at 12:21 AM 0
Share

You can't use a rigidbody along with a character controller. a character controller IS already a collider. You shouldn't attach any collider. A character controller is always a capsule.

Use a CharacterController if you want to direcly control your character. You can apply gravity manually. The character controller package that comes with Unity shows how it can be done.

An alternative is to use a rigidbody with a collider. However a rigidbody is a physics object. It can be pushed or influenced by other rigidbodies and should be controlled by adding forces. If you don't like that behaviour, use a CharacterController.

avatar image Hor · Jun 23, 2012 at 12:23 AM 0
Share

I just realize that my gizmo is in a strange way.

Looking at this screenshot: (http://i46.tinypic.com/2i1o749.jpg), we can see that i have the "x" where it need to stay, but the "Z" is in the "y" location.

I guess this is messing me up.. but i coudnt put my terrain in the way that X be my horizontal line, and Y my vertical.. Danm, i guess im confused ;/

avatar image aldonaletto · Jun 23, 2012 at 05:11 PM 0
Share

The object in the screenshot is a terrain, and you're seeing its Local axes, which obey the Rotation field - but the terrain completely ignores it, thus the axes may have any orientation independently of the terrain.
If you want an infinite vertical background for a side-scroller XY game, create a skybox with your background image. If you need the background at some specific position, use an Unity plane ins$$anonymous$$d.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Input.GetAxis doesn't seem to move me in the direction I am facing 2 Answers

Click to move a character in a terrain 1 Answer

How to have a sphere roll/be affected by friction 0 Answers

Character Controller / Charactor Motor has no inputs? 1 Answer

How to add explosion force to player? 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