• 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 POL34 · Apr 15, 2012 at 11:35 PM · movementspherestuck

Forward movement question

Hello,

The main character of a platform game I am working on is a sphere. The only control the player has over their sphere is moving to the left or right which works fine right now. I am using a Transform.Translate function to move the ball forward at a constant speed, but because it rotates along the z axis it pushing towards the ground for part of each rotation and digs itself into the terrain and literally gets stuck. I've tried several different fixes, but none of them have worked. Any ideas?

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 IgnoranceIsBliss · Apr 16, 2012 at 12:01 AM

I think we would need to know more about your situation and the code you are using. I'm assuming you are using Unity physics (you have a Character Controller or a RigidBody on your sphere and are colliding against a Terrain?)

The most common reason for getting 'stuck' like this is that you have use Translate and thrown yourself 'into' the terrain.

Rather than using the normal translation functions, try using a CharacterMotor.

Check the code for the FPS controller and some of it's friends - you'll notice one spot where it has a line like this...

 motor.inputMoveDirection = transform.rotation * directionVector;


The CharacterMotor class knows all about avoiding collisions, sliding and avoiding terrain. By applying your user input to this rather than calling Translate, you'll give the CharacterMotor the chance to say 'No - That Will Get Me Stuck'. Instead, it will properly avoid terrain, slide down steep portions and will simulate physical properties like mass and inertia.

So if you were wanting to move your ball 'left' in response to a button press, you would say...

    motor.inputMoveDirection = new Vector3(1,0,0);


Of course, you may need to change the axis I've shown here depending on how your scene is set up. Take a look at the FPS Controller for more ideas, since it shows you a pretty basic example of how to make it work.

Comment
Add comment · 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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Can a ball rotate without moving and changing its axis? 1 Answer

moving spheres on a plate 0 Answers

Sphere overlaps vertical box collider and stutters 1 Answer

Creating bb-8 like movement. 1 Answer

Character Can't Move After Teleporting? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges