Reset rotation of gameobject

Hey,

so I’m trying to reset the rotation of my board-gameobject, with walls as child-objects. There is a ball which the user navigates around a labyrinth and if the ball hits a hole - the ball should have its velocity and position reset and the board should have it rotation reset.

For some reason, I cannot reset the rotation of the board in my Reset-method, which is called when a hole is hit.

this is my code:

public void Reset(){
	print ("Reset-method called");

	count++;
	setCountText ();

	board.transform.rotation = Quaternion.identity;

	ball.GetComponent<Rigidbody>().velocity = Vector3.zero;
	ball.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;

	ball.transform.position = new Vector3 (startZone.transform.position.x, ballY, startZone.transform.position.z);
}

ah ok. In this specific scenario I have a pool of particles. It was screweing up their animation when I deactivated them and tried to restart it all again, and was wondering whether it was a good idea just to turn the sprite renderer off and leave them being moved via their script, so that when I turn the renderer back on they will still be there. But, that would mean I would be leaving it on for all of the space ships, as they will all be created as a pool at the start of the level and intended as a webGL game.

1 Answer

1

Can’t tell exactly what could be an issue but have you tried new vector3(0,0,0)?
May be this could work and if it doesn’t kindly share more details because your code looks fine.

Bro you are making a mistake by rotating your board in an update method without applying any check. Actually Update is called continuously even if you call your Reset() method. What you need to do is use a bool for board.transform.rotation = Quaternion.Euler (spinVert, 0, spinHori); Whenever your ball hits the hole this should stop updating too. I hope you got my point, if you still face problem do tell.