I´m a beginner coder who’s working on his first game
I´ve a Movement method whose purpose is to move an item to the left and right along the x axis.
The method below is a component on a GameObject that without this code, is instantiated at a random position on the x axis.
GameObject newObstacle = Instantiate(obstacles[RandomObstacleCounter], new Vector3(Random.Range(-8,8), obstacleIndex * distanceBetweenObstacles), Quaternion.identity);
The GameObject that is instantiated is a Prefab that has a script associated to it.
If I comment the code below out, the GameObject is instantiated at a random position in the x axis between -8 and 8.
With the code below, the GameObect is always instantiated at 0,0.
Vector2 specialItemPosition = transform.position;
specialItemPosition.x = Mathf.Cos(_angle) * 5;
transform.position = specialItemPosition; _angle += Time.deltaTime * _xSpeed;
I think my issued is somewhere in the second line…
I´d like Mathf.Cos(_angle) * 5 not necessarily to be oscillate between 0 in the x axis, rather,
I´d like to add a random value (Random.Range) between -8 and 8 (for example).
Help would be appreciated.