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 GregPDesUGD · Aug 24, 2014 at 09:42 PM · colliderspriteruntimepixel art

How to change a sprite collider at runtime

Hello there!

I am a newcomer to the Unity Editor, and right now building a demo of a side-scrolling shooter game, with pixel art all done using GraphicsGale by HUMANBALANCE Ltd. I'm coming across something that I need to know about before I can try it out in programming.

I have a game object representing the player that holds one sprite renderer, but as the game progresses, depending on how fast the ship goes up and down in space, the sprite changes. What I mean is, at the start, the ship sprite is horizontal. But when the player decides to move up, for example, the program checks both vertical and horizontal speeds and calculates the angle by tangent inverse. I have three states in both directions that approximate to 15°, 30°, and 45°; depending on what the calculated angle is, the sprite is replaced by one that is inclined appropriate to that angle. (I am not directly rotating the game object from the Unity Editor; I've tried this on another sprite, and the overall resolution of that sprite when rotated is too high compared to the low pixel res I wanted. I want to retain low pixel quality where in all sprites of the game, there is one size of a pixel that makes them stand out instead sprites consisting of differently-sized pixels, creating a distracting effect.)

As the sprite is changed, the collider has to be changed as well to avoid problems such as player damage from a projectile that has collided with a collider that a section of it is not in the visible sprite.

Anyway, because in the Inspector Pane, I can only hold one sprite renderer at the time, but can hold multiple edge colliders, is there a way I can load one of the edge colliders as the sprite is changed without having to go through recording all the points down and pasting them in the code for instantiation? When I build my game, are all my sliced sprites saved separately, in addition? (I am using edge colliders, because I ran into problems with the polygon collider, where it cannot cover the entire spaceship as one polygon. Instead, there are several polygons together that create empty spaces.)

In full detail, I plan to use seven edge colliders and because of some animations, 224 sprites for my player; 32 for each of the seven angles. (-45, -30, -15, 0, 15, 30, 45, all in degrees)

Please let me know!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Vardan Meliksetyan · Aug 26, 2014 at 12:54 PM

Hi GregPDesUGD, I have idea but I didn't shure is it good solution for your project when you need to change sprite collider when sprite is changed you can delete and add collider component. But when you need do this often is can work in your project very hard

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 GregPDesUGD · Aug 26, 2014 at 02:45 PM 0
Share

I understand your answer, just let me give an ideal example. In any full 2D pixel game, whenever a game scene is to be loaded, I think it is much better for all the sprite colliders to be loaded for each individual sprite, rather than have the current collider be deleted and have a new one instantiated at runtime.

As a guess, it's not always a good idea to create an instance of a class such as a sprite collider during actual gameplay because it will reduce performance and more likely put in a new game bug for not being able to put in a collider fast enough.

Personally, I prefer that all the colliders are instantiated at the same time when a scene is loaded, saved into a temporary array, and when necessary, replace the sprite's current collider object with that of an appropriate one. When the user quits the game scene, the array is released from being referenced and the garbage collector recycles it into new memory.

avatar image
0

Answer by knudsjef · Nov 01, 2014 at 04:56 AM

just rotate the renderer through code

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

Creation of Edge Colliders at Runtime 0 Answers

Chewing gum Physics Material 2D 1 Answer

Sprite.Create() with outline tolerance? 1 Answer

Character animation ghost pixels 1 Answer

Pixel art sprites messed up, How do I fix it? 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