Hi,
I am trying to shoot projectiles from the player’s position, who is on a surface of the sphere, and make the projectiles rotate around the sphere. Here’s (sloppy) 3D representation:
Same stuff but from the side view:
The projectiles rotate correctly when initializing projectiles from emit position 1 a.k.a initial position.
When I translate player’s position and initialize a new projectile, it has smaller radius. The required direction should be the direction in which the green arrow is pointing at.
The code for rotation I use:
public float projectileSpeed = 20f; // Speed of the projectile
public GameObject projectile; // Projectile's template
private GameObject aProjectile; // Instantiated projectile
public Vector3 centerPosition; // origin (0,0,0)
void Update() {
if (Input.GetButtonDown("Fire1"))
{
Shoot(transform.position);
}
if (aProjectile != null)
{
var axis = Vector3.up; // does not matter, in which direction... Let's go up, for instance...
aProjectile.transform.RotateAround(centerPosition, axis, projectileSpeed * Time.deltaTime);
}
}
public void Shoot(Vector3 fromPosition)
{
aProjectile = Instantiate(projectile, fromPosition, Quaternion.identity) as GameObject;
thisTransform = aProjectile.transform;
}
Camera is always facing the sphere. I’ve omitted player’s movement script around the sphere for brevity.