Question by
JiskaBaeten · May 11, 2017 at 09:17 AM ·
positionorbitmathf.sin
Using Sinus function to get position, but result seems off
So I'm trying to make a Katamari based game and managed to make my cam orbit around my ball. I'm using this cam to determine the position of the character that's 'pushing' the ball (so it orbits in the same way around the ball).
I figured that using Matf.Sin could be used to do this (see image), but I'm getting the wrong result. I think the angle of the cam is the issue but I'm not sure. LockPos is a point that's always at the bottom center of the ball.
I'm really stuck on this and would appreciate some help.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FollowPlayer : MonoBehaviour
{
//used for the beetle following the ball, rotates with cam
//DOESN't WORK YET
public Transform lockPosition;
public GameObject cameraOb;
private Vector3 offset;
private Vector3 beetleOffset;
private float distance;
private float testSin;
void Update()
{
beetleOffset = new Vector3(cameraOb.transform.position.x, lockPosition.position.y, cameraOb.transform.position.z);
distance = cameraOb.transform.position.y - lockPosition.position.y;
if (cameraOb != null)
{
testSin = Mathf.Sin((cameraOb.transform.rotation.x) * Mathf.Deg2Rad*100) * distance; //*100 since degrees are in comma
}
transform.position = beetleOffset - new Vector3(0f, 0f, testSin);
//rotates with cam so beetle is always looking at the ball
transform.LookAt(lockPosition.position);
}
}
Comment