- Home /
Delayed rotation when i use transform.rotate
I am working on rotating an object. My code is working good but for the first time it takes around 10 seconds to start to rotate. I don't know why this is happening.Can anyone know about this ? Thanks in advance for your help. My code is like this ,
if(Input.touches.Length > 0) {
Touch tchEvent = Input.touches[0];
if(tchEvent.phase == TouchPhase.Began)
{
m_v2LastPoint = tchEvent.position;
}
else if(tchEvent.phase == TouchPhase.Ended)
{
Ray rRay = Camera.main.ScreenPointToRay(Input.touches[0].position);
if (Physics.Raycast(rRay.origin, rRay.direction * 10, out m_rhHit))
{
for(int iIndex = 0; iIndex < Global.iNumOfCircles; iIndex++)
{
if(m_rhHit.transform.name == m_agobjBlock[iIndex].name)
{
if(m_gobjSelectedObject != null && m_rhHit.transform.name != m_gobjSelectedObject.name)
m_gobjSelectedObject.renderer.material.mainTexture = m_txtrNormal;
m_gobjSelectedObject = m_rhHit.transform.gameObject;
m_gobjSelectedObject.renderer.material.mainTexture = m_txtrSelected;
break;
}
}
}
}
else if(tchEvent.phase == TouchPhase.Moved)
{
fOffset = tchEvent.position.x - m_v2LastPoint.x;
m_gobjSelectedObject.transform.Rotate(0, 0, fOffset * 1f);
m_v2LastPoint = tchEvent.position;
}
}
Answer by abi-kr01 · Feb 17, 2014 at 06:07 AM
last time when i was using touch to rotate the game object called string i used Time.delta time i think you should use time.delta time concept it gives float value if it don't work with time see other help available on Time factor , with modified foffset value your code should look something like this
m_gobjSelectedObject.transform.Rotate(0, 0, fOffset*Time.delta time);
at lest try it work with me may work for you tooo
Hi abi.kr01, I have used Time.deltatime but still it gets delayed to rotate for the first time. Can you please tell the reasons why this is happening? I am trying to find a way to this issue for last one week and still...... I want to finish this project as early as possible.
sorry for late reply, apply your raw(own code) code in Fixed Update function because it runs faster hen other updates.so when it start faster and gets executed faster.hope this works fine and u will get result.