Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 nutntubear · Jun 06, 2016 at 07:12 AM · javascripttransformtransform.positioncharacter movementtransform.translate

Alternative to using transform.translate and transform.position for moving objects exact values?

Is there a way to move an object a certain amount without using transform.position or transform.translate? I'm working on something that would look like the game Rogue, with ASCII art-esque sprites. I'm using a simple script to make the player move, just using transform.position to move them. However, both transform.position and transform.translate ignore box colliders, like those I've set on the player and the walls in the level I've built. If it would help if I post my code, I definitely can. I just want to know if there was a way to move the player an exact amount that still respects box colliders.

Alternatively, if there isn't a good way of doing this, would there be a way to build this entirely with something like a textmesh? And, in Javascript, how would that work?

Update: I've tried using Rigidbody2D.velocity and such, but it always comes up slightly off, blocking the player from moving into exact areas, and after a while of movement, becoming noticeably off the grid.

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
1

Answer by Eudaimonium · Jun 07, 2016 at 12:47 AM

If I'm understanding your problem right, you basically want to move an entire tile's worth of distance at once, no transition in between?

Then you cannot rely on the internal physics engine and you might as well remove all colliders and rigidbodies.

Instead, if you know your world is made up of regular tiles, you can build position and collider arrays.

For example,

 bool[][] colliderGrid;
 Vector3[][] positionGrid;

At your Start function, generate these arrays according to the tiles present. Then, simply move your player according to indices of the tile you're on and where you want to go. Also check if next tile is a collider according to the same indices.

Then simply use transform.position to move to the precalculated area, instead of using incremental movements which will result in movement error after some time due to nature of floating point numbers.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

transform.Translate() effect is being reverted 0 Answers

Vector2.moveTowards but only on one axis 1 Answer

How to shift the player to a definite position in the x-axis using key presses? 1 Answer

Why is rotation offset 1 Answer

Moving an object on different axis? 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