• 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 $$anonymous$$ · Jul 05, 2019 at 09:22 PM · 2d2d game2d-platformer2d sprites2d rotation

Instantiate a GameObject with a specific Z rotation

Hi there ! First, sorry for the english mistakes I'm not from England or wathever. Here is my problem : I'm making a demake (NES style) of Portal from Valve and my problem is when I create a portal. When I'm instantiate it, the portal will appear in his origin rotation. I tried to impose a specific Z rotation to the portal but it will always appear with the same Z rotation. What I want is when the portal appears on a wall the portal is vertical and when the portal appears on a ceiling it is horizontal. I saw on Internet to use Quaternion but I don't understand it... I put some screenshots of the game and the portal's script for you to understand my problem better. Thanks to the poeple who will help me :)

Game view > https://ibb.co/6Wdf6xY Script > https://ibb.co/D8x2pj7

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

Answer by mehamednews · Jul 06, 2019 at 02:10 AM

I suggest using a raycast to check if the surface is a WALL or CEILING, Then Change the rotation of the portal according to that

To set a specific rotation (while instantiating the portal) use "Instantiate" And to check the type of surface use "raycasting"

Comment
Add comment · Show 2 · 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 misher · Jul 06, 2019 at 07:19 AM 0
Share

Yeap, check the normal of the surface behind portal and make portal's transform.forward = normal. Ofc make sure your portal's forward direction is the right one, it should be z positive i guess.

avatar image $$anonymous$$ · Jul 06, 2019 at 11:00 AM 0
Share

Thanks @mehamednews. I tried collisions tags with raycasts and it works ! But I didn't understand everything about raycasts and I hate when I don't understand my script ahah. So what I did is if the bullet (blue or orange) hits a wall : Instantiate(blueBullet, transform.position, Quaternion.Euler(new Vector3(0, 0, 0))); and if it hits a ceiling : Instantiate(blueBulletl, transform.position, Quaternion.Euler(new Vector3(0, 0, -90))); The bulletes have rigidbody2D attached to. $$anonymous$$yabe it's not the best way to do that but I understand better compared to raycats. But thanks for your help it helped me anyway and I hope it will help other people :)

avatar image
0

Answer by Marioooo · Jul 06, 2019 at 06:48 AM

you can use qaternion.AngleAxis its a quaterion unit, but you can set it as a axis rotation, easy to understand https://docs.unity3d.com/ScriptReference/Quaternion.AngleAxis.html on the quaterion section, you can declarate a qaternion.angleaxis and set the z value

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

234 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 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 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 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 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 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 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 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 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 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 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 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 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 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

2D Sprite Fillup without using UI 1 Answer

Destroy a gameObject in the scene if instantiate the same gameObject 0 Answers

Exchange player position to only 3 possible places with a platform 1 Answer

2d shooting problem 1 Answer

How to blur 2D background sprites? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges