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 hapynoid · Nov 10, 2016 at 08:13 AM · spriteunity 2dinvisible

Unity 2D Sprite is invisible.

Whenever I attach this script to my game object and I start the game the sprite turns invisible. Everything else seems fine.

public class FollowPlayerBullet : MonoBehaviour {

 public float speed;
 private Transform lookAtTarget;

 void Start()
 {
     GameObject tar = GameObject.FindGameObjectWithTag("Player");
     if (tar)
     {
         lookAtTarget = tar.transform;
     }
 }


 void FixedUpdate()
 {

     transform.LookAt(lookAtTarget);
     transform.Translate(Vector3.forward * speed * Time.deltaTime);

 }

}

alt text

alt text

It is not the destroy bullet script as it is the same without that script. I tried changing up the sorting layers and that didn't work. The only thing that seems to be causing the sprite to disappear is that script. Also any improvements on the script itself would help too, it should be a bullet that is instantiated and follows the player for five seconds. Thank You

img1.png (72.8 kB)
img2.png (45.5 kB)
Comment
Add comment · Show 2
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 aditya007 · Nov 10, 2016 at 10:02 AM 0
Share

$$anonymous$$aybe it got rotated by the lookAtTargettransform, and is facing a different axis making it look like it's invisible. Check the gameview in 3D mode at runtime.

avatar image hapynoid aditya007 · Nov 10, 2016 at 10:33 AM 0
Share

Wow so I did check the 3D mode and the sprite was still visible. The sprite seemed to be completely flat. Hmm thanks a lot for that I might be able to fix it now. If you have any ideas of how to fix this it would be helpful. Thanks a lot :).

2 Replies

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

Answer by snorcack · Nov 10, 2016 at 10:32 AM

I tried the script with the same components and the sprite remains visible to me. However, since you are using the lookat method, most likely the sprite gets oriented orthogonal to the camera and becomes invisible. I modified the script slightly and got this result.

https://gfycat.com/LimitedDamagedCuttlefish

here is the modified method.

 Vector3 direction = lookAtTarget.position - transform.position;
 
         Quaternion toRotation = Quaternion.FromToRotation(transform.right, direction);
 
         //transform.LookAt(lookAtTarget,Vector3.right);
         transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, rotateSpeed * Time.time);
         transform.Translate(Vector3.right * speed * Time.deltaTime);


Hope this helps !

Comment
Add comment · Show 1 · 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 hapynoid · Nov 10, 2016 at 11:28 AM 0
Share

Thanks this helped a lot. Prior to asking I got really frustrated. To think the answer was this simple is kinda funny. This community is great and I got a response really fast, it makes me just want to code more and make amazing games in the future. Ill be sure to ask more questions if I get stuck.

Thanks so much ^.^

avatar image
1

Answer by aditya007 · Nov 10, 2016 at 11:25 AM

@hapynoid continuing my comment. You can solve this problem by following methods

  1. changing the rotation of sprite at runtime (so it won't affect your project atm) and check when it is visible and note down the rotation values. Afterwards, stop the game and add the following line to your script right after transform.LookAt(lookAtTarget);

    transform.rotation = transform.localEulerAngles = new Vector3(x,y,z);

where x,y and z will be angles you noted down at runtime.

This is not the desired way, because it would make your lookAt function render useless, as you'll need to change the rotation, making it face a different way.

  1. You should set all your gameObjects in x-y axis (in 2D), so their's no rotation in z axis. That would make the lookAt function better, because you won't have any z-rotation and your sprite will be visible.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity2D resize the sprite 0 Answers

Cant access the Image icon from class 1 Answer

2D GAME (non UI object) for every pc resolution 0 Answers

Fire emblem like path drawing for a 2D tile based strategy game? 0 Answers

If i flip the scale from a sprite, how do i make my game object child flip aswell? 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