- Home /
How can I move an object based on a global axis?
Hello,
I 'm trying to make a flying- beetle game and I want my bugs to fall towards the ground when the die but I can't think/find out how to move them on global axis. I use accelerator input from android so my Y-Axis change on my player. So when it dies, it goes up or left / right. It's a pretty funny glitch to watch but ruins the reality of the game.
Any ideas on how to fix it?
Thanks In advance!!! : )
void FixedUpdate()
{
if (currentHealth <= 0 && isDead == false)
{
isDead = true;
BeetleAudio.PlayOneShot(BeetleDieing);
}
if (isDead)
Death();
}
void Death()
{
anim.SetTrigger("Die");
playerRB.isKinematic = true;
fly_Movement.enabled = false;
transform.Rotate(new Vector3(0, 0, 0) * Time.deltaTime);
if (transform.position.y >0) //Check if above ground before and while sink
transform.Translate(new Vector3 (0, -fallingSpeed, 0) * Time.deltaTime);
else
transform.Translate(new Vector3(0, 0, 0));
}
Answer by Garazbolg · Jun 12, 2017 at 11:30 AM
By delfault the Tranform.Translate method use local space. But there is a second optional parameter that allows you to choose the space like this :
transform.Translate(new Vector3 (0, -fallingSpeed, 0) * Time.deltaTime ,Space.World);
What is the 'space.World' ??? Actually, I want to move an NPC in Global axes while rotating them in Local axes. How do I do that??? I tried this..
transform.Translate(new Vector3 (speed*Time.deltaTime, 0 , 0);
It doesn't work. Can you Help me? Thanks in advance.
There is several methods for rotating an object, if you want to apply a constant rotation you should use transform.Rotate();
example:
transform.Rotate(15,0,0)
explanation:
This rotates the transform along it's local X-axis by 15 degrees every frame.
Yes, Thank You. What I actually want to do is, rotate an object on the local axes. as you mentioned, I used " transform.Rotate(0,180,0);" I also want to move it forward. But for that I cant use local axes, because the axes are constantly rotating and the object won't neatly move forward on the same local axes. Hence I want to know how to move them on the global axes. Do you know, how to move on global axes? Thanks in advance.