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 Milun · Jun 26, 2014 at 03:47 PM · graphics

Having a Sprite's position be different to it's prefab's

Hello. I've been using Unity for about 2 years now, and have a difficult question to ask.

I am making a 2D game, and have a rigidbody object. This object has a SpriteRenderer attached to it, so naturally, when the object moves, it's sprite moves with it.

What I want to do however, is have the object move normally (smoothly), but have the sprite move jarringly, giving off the illusion that the object is moving jarringly.

For example, when the object moves from x = 0.0 to x = 10.0, it goes 0.1f, 0.2f, 0.3f etc. But the way I want the sprite to move is for it's position to be the Mathf.Floor() of x, so: 1, 2, 3, 4 etc.

I've searched many topics on this, but there doesn't seem to be a way to move a SpriteRenderer independent of its GameObject. I would make the GameObject itself move jarringly, but that would interfere with it's rigidbody behavior.

This issue's been bugging me for days now. I really appreciate any and all help on this. Thanks in advance.

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

Answer by Jeff-Kesselman · Jun 26, 2014 at 03:48 PM

A SpriteRenderer has no position.

The only things that have position in the world are game objects.

My suggestion is that you make a child object to hold the sprite and adjust its position as you want.

Comment
Add comment · Show 3 · 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 Jeff-Kesselman · Jun 26, 2014 at 04:53 PM 0
Share

In the editor, create an empty game object, then drag your sprite object over it in the hirearchy window.

or in code do something like this:

 GameObject parentObj = new GameObject();
 mySprite.transform.parent = parentObj.transform;
avatar image Milun · Jun 26, 2014 at 05:01 PM 0
Share

Hm... could I get an example of that please? Specifically, how I would assign it in the inspector.

Do I just make the object instantiate a blank GameObject at runtime and assign a sprite to it?

avatar image Milun · Jul 02, 2014 at 12:55 AM 0
Share

Thankyou so much! Unity makes it a little awkward, but it solved my problem.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to get the same good graphic as in Cinema 4d? 1 Answer

Would learning some GLSL help with Unity Shading? 1 Answer

How to create a plow of fields ? 0 Answers

Using stencil buffer with OnRenderImage()/Blit 0 Answers

LWRP - Placing markers on terrain and gameobject dynamically 0 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