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 Posthuman-Wizard · May 08, 2013 at 12:23 AM · collisionmovementphysicsrigidbodymoveposition

Calling Rigidbody.MovePosition, no movement at all

Okay, so, this is weird. I added a line of code to my project last night that will move an object about one unit to the right every frame with Rigidbody.MovePosition(), and everything worked fine and dandy. Saved, quit, log back in the next day, and it's not doing anything, even though the line of code is apparently being called.

Using Transform.translate works, but I desire the collision detection that comes with doing things with a Rigidbody. Manually assigning the transform's position every frame works, and allows for semi-functional collision detection, but I don't want to use that, because I desire smooth and accurate collision detection for this game.

I don't see why this would work one night and the next, it doesn't. I've checked the GameObject; the rigidbody is still attached to it, and it is not Kinematic, nor is it using gravity. Any help would be greatly appreciated.

Update:

To put this into context, this game is top-down and two-dimensional. Here is my movement code:

 this.rigidbody.MovePosition(new Vector3(this.rigidbody.position.x + this.currentSpeedX,this.rigidbody.position.y + this.currentSpeedY,this.rigidbody.position.z));

(currentSpeedX and currentSpeedY are set to 1.0f if the necessary keys are pressed and 0f otherwise; this is being called every frame)

This does not work. However,this works perfectly:

 this.transform.position = new Vector3(this.transform.position.x + this.currentSpeedX,this.transform.position.y + this.currentSpeedY,this.transform.position.z);


Here is the relevant information from my player GameObject:

alt text

prefabinfo.png (20.6 kB)
Comment
Add comment · Show 5
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 Jeaper · May 08, 2013 at 05:52 PM 0
Share

A code piece and a picture of your prefab would be helpful.

avatar image Posthuman-Wizard · May 10, 2013 at 12:44 AM 0
Share

I have updated my original post with relevant information.

avatar image cobertos · May 10, 2013 at 12:49 AM 0
Share

Perhaps freezing z is the issue? In unity, y is up and the x-z plane is the horizontal plane.

avatar image Posthuman-Wizard · May 10, 2013 at 01:01 AM 0
Share

Unfreezing Z didn't do anything. Everything is angled and positioned with X being left and right and Y being up and down, so I didn't think that would work.

avatar image meat5000 ♦ · Dec 07, 2017 at 06:47 PM 0
Share

Collider stuck in floor?

Using GetComponent appropriately to capture the actual Rigidbody in question?

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by mrEagle · Dec 07, 2017 at 03:18 PM

Being late to the party:

I forgot to turn off some constraints on my rigidbody. As they are folded by default in the inspector (and you may have folded your rigidbody component altogether), you may want to double check these options :)

My experience is that Rigidbody.movePosition is agnostic to where it is called, the effect is the same for Update and FixedUpdate. I guess the morale of the answers so far, is that if your object does not move, the physic engine is probably preventing it for good reasons.

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

Answer by codecranker · May 11, 2013 at 12:14 AM

Are you calling MovePosition in Update or FixedUpdate?

The doc says it should be in the FixedUpdate. Thats the update for physics based movements. http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.MovePosition.html

Also, can you try checking the 'Is Kinematic' on your RigidBody component to see if that makes any difference?

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

Answer by Rainbirth · Jul 20, 2016 at 02:27 PM

I had the same problem to solve it make sure that it isn't a child of an object that is moving its position in a Fixed update.

I had this situation that was blocking movement

Parent -> moving its transform with one script in its fixed update. ----> rigidbody child using the moveposition in its fixed update <--- this doesn't work.

To fix it just use Update in the parent to move its position.

I hope this helps.

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

Answer by IgorAherne · Mar 08, 2019 at 01:57 PM

Also check that rigidbody's "freeze position" is not ticked (in its Inspector window).

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.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Keep Horizontal Momentum after Jump 2 Answers

My Character Moves through walls 3 Answers

Stopping my player from moving when hitting a wall. 5 Answers

What is the best way to move the player with physics without using MovePosition? 0 Answers

is there a way to move a rigidbody with something like moveposition without clipping through collider? 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