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 superluigi · Jul 02, 2013 at 11:13 PM · transformnoob

How can I move an object without translate or addforce?

I need to move a platform in a 2d game however translate makes it go through my CharacterController player if I move the platform up. The platform is not a rigidbody as I don't like the smooth acceleration and deceleration they have. I have seen scripts where they move objects with transform.position but I can't find any. I need it to move in the same way that translate makes it move.

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

3 Replies

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

Answer by robertbu · Jul 02, 2013 at 11:23 PM

Moving your platform using transform.position is likely to have the same problems as transform.Translate(). To get rigidbody movement without the smooth acceleration of AddForce() just assign the velocity directly. For example to go in the up direction:

 rigidbody.velocity = Vector3.up * speed;

This will cause an immediate jump to the specified velocity without any acceleration. If you want this velocity to continue even after other forces come into play (such as a collision with another Rigidbody) you can assign it in FixedUpdate().

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 superluigi · Jul 02, 2013 at 11:44 PM 0
Share

While this does work it moved up for half a second and then it began to fall down. I locked the rotation cause it would rotate when my player would land on it. I don't understand why it falls or rotates if my player doesn't have a rigidbody. Btw I put the code in fixedupdate cause I read that when an object has a rigidbody attached you use fixedUpdate ins$$anonymous$$d of update.

avatar image robertbu · Jul 02, 2013 at 11:51 PM 0
Share

Without a clear understanding of the nature of your platforms and the player, I cannot say what is going on. Note by default gravity is turned on for Rigidbodies, so your platform will fall if the force or setting the velocity is removed. In addition if you want to have the Rigidbody stop, you can set the Is$$anonymous$$inematic flag to true.

avatar image superluigi · Jul 03, 2013 at 12:04 AM 0
Share

I turned gravity off. I also noticed that when its moving up my CharacterControllers collider is going through the platform somewhat.

avatar image superluigi · Jul 03, 2013 at 12:06 AM 0
Share

$$anonymous$$y player has a CharacterController attached and the platform is simply a box collider, not a trigger, rigidbody with no gravity and not kinamatic.

avatar image
0

Answer by markpdolby · Jul 02, 2013 at 11:18 PM

Try using Vector3.MoveTowards to move your object, the docs have an example of how to use it here: http://docs.unity3d.com/Documentation/ScriptReference/Vector3.MoveTowards.html

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 Radon · Jul 02, 2013 at 11:19 PM

I always use the following script to change the location of an object:

 transform.position = Vector3(X, Y, Z);

make sure to change the X, Y, and Z terms to where you want your object to be transformed.

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

17 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Move Objects arranged in Circle Forward 1 Answer

Random number that doesn't repeat. (javascript) 3 Answers

Alarm lights not changing 1 Answer

a child object that inherits only position from parent 2 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