Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Quaternions and Instantiate, Froze one Axis

Discussion in 'Getting Started' started by darthachill, Mar 28, 2015.

  1. darthachill

    darthachill

    Joined:
    Jan 25, 2015
    Posts:
    27
    Character Controller Cast Spell, which goes forward, until spell touch the ground, After colision in this spot with Earth, I create in Script below Wall. The problem is that The Wall is always skew.
    How Can I fix it ?


    Code (CSharp):
    1. public class StoneWallEffect : MonoBehaviour
    2. {
    3.     GameObject SpellObject;
    4.     void Awake()
    5.     {
    6.         SpellObject = Resources.Load<GameObject>("Prefab/Spells/StoneWall/StoneWallEffect");
    7.     }
    8.     void OnTriggerEnter(Collider other)
    9.     {
    10.         if (other.name.Equals("Terrain"))
    11.         {
    12.             GameObject Wall = Instantiate(SpellObject, transform.position, ???????????????) as GameObject;
    13.         }    
    14.     }
    15. }


    In my Prefab Wall I set Transform( Position & Rotation) to 0,
     
  2. Kondor0

    Kondor0

    Joined:
    Feb 20, 2010
    Posts:
    596
    Did you tried Quaternion.identity?
     
  3. darthachill

    darthachill

    Joined:
    Jan 25, 2015
    Posts:
    27
    Yes I tried, It doesn't work because, every time I createdWall, it has always the same rotation, like Prefab. Now I Try something like that:

    Code (CSharp):
    1. public class StoneWallEffect : MonoBehaviour
    2. {
    3.     GameObject SpellObject;
    4.  
    5.     Vector3 PlayerPos;
    6.     void Awake()
    7.     {
    8.         SpellObject = Resources.Load<GameObject>("Prefab/Spells/StoneWall/StoneWallEffect");
    9.         PlayerPos = transform.position; // In this place I save information about Player Position, when object is born."Object" I mean magic ball which I cast
    10.     }
    11.  
    12.     void OnTriggerEnter(Collider other)
    13.     {
    14.         if (other.name.Equals("Terrain"))
    15.             GameObject Wall = Instantiate(SpellObject, transform.position, Quaternion.LookRotation(PlayerPos - transform.position, Vector3.up)) as GameObject;  
    16.     }
    17. }
    Created Wall looks better. But it is still problem with that, wall is not perpendicular to the Ground, I marked it on the picture.
     
  4. Ness

    Ness

    Joined:
    Oct 1, 2012
    Posts:
    182
    I would start debugging this from instantiating a simple cube(with quaternion.identity)to separate whether this is a scripting issue or model issue. My guess is that it is connected to parenting/parented game objects.