Hey without going in to too many details I’m trying to get my project up and running again (probably a bad decision tbh).
I’ve changed a lot of the code. I have video of the problem but be sure to check the Youtube description box because OBS is crap and never works the way it should.
The problem is I have this four corners box which should be just over the actual mouse position. To achieve this I do a computation which involves subtracting half the screen width and height from the mouse position. This ought to get me a relative value for the mouse position.
I do some other things like establishing a maximum radius for the mouse input (mouseReduced variable).
I have investigated every relevant variable for every piece of code related to the positioning of these and I still don’t know whats wrong. I’m at my wits end!
I’ve determined that most of the other things are irrelevant. I don’t understand how or why the pointer box can be so far off, because it gets assigned the value returned in that calculation.
The relevant lines in MouseFlight.cs are in the GetInput() and Awake() functions.
code:
using UnityEngine;
using System.Collections.Generic;
public class MouseFlight : MonoBehaviour
{
/*The main flight control script. May need to be made generic for AI in the future (or have the AI emulate this behavior somehow).
//BOTTOM LINE: Every one of these scripts needs to be able to function on its own. They cannot be
interdependent if new subsystems are to be implemented.
* Also note that to utilize loose coupling, these variables shall be public only to be set in the Unity editor. As a rule no other script should access these without going through a get/set method!
* */
float speed; //Speed of the ship in unity units
float thrust; //Thrust is how much power is going through the engines. Different from speed??
float radialLimit; //Limits the distance from the center of the screen.
float thrustPercentage;
public float maxReverseThrust, maxForwardThrust;
bool mouseFlightFlag = false;
bool readyCruiseFlag = false;
Vector3 playerMoveVector;
public Camera mainCamera;
bool cruisingFlag = false;
Vector2 screenCenter; //Container to use as a reference when doing math to find the mouse
public float baseThrust;
public float cruisingSpeed;
float baseInverseThrust;
public float maxThrust, minSpeedDelta, minThrustLevel;
public float cruiseChargingTime;
public float screenRatio; //MUST BE BETWEEN 0 and + 1!
public float maximumAngularSpeed;
public float cameraFollowDistance; //Why do we have two similar vars??
public float camerZoomStep;
public float acceleration;
/*Useful for making all turns have a maximum
distance/turn rate regardless of where the mouse is (ie. a corner of the screen where
the distance from center would be at its greatest) */
public float turnSpeed;
public float sidestepSpeed;
public float minScalar; //NOTE: revisit!
public float cameraLocalDistance, cameraLocalHeight; //Used to find new camera position
public float lookSpeed;
public float rollSpeed;
//In the future: Should cause the CameraLook to be situated at the same position as the camera in all configurations, then transform.LookAt() the LookTo gameoject whcih will be the focus of the camera's orientation
public Transform cameraOrbiter; //The purpose of this Transform object is to provide a third person obiting feature. This object should be centered on the player ship object
Vector3 offsetVector = Vector3.zero;
float thrustLevel = 0f;
float prevCruiseTimeStamp;
Transform ship;
float connectorScalar;
const float cooldown = 0.5f;
Vector3 translation;
bool mouseLookFlag = false;
bool revertCameraOrientationFlag = true;
bool returnToForward = true;
float lastFlightToggle;
bool re_enableMouseFlight;
float targettingResetLimit = 0.25f;
float lastTargetResetTimeStamp;
List<GameObject> targetList = new List<GameObject>(); //To contain a list of all the destructible objects in the scene.
int listIndex;
Rigidbody rb = new Rigidbody();
float connectorAngle;
Vector3 keyboard;
public Vector2 mouseReduced, actualMousePosition;
//-=-=-=-=-=-=-=[Getter/Setters]-=-=-=-=-=-=-=-=-=-=-=
public float RadialLimit
{
get
{
return radialLimit;
}
}
public Camera MainCam
{
get
{
return mainCamera;
}
}
public float Velocity
{
get
{
return speed;
}
}
public bool Cruising
{
get
{
return cruisingFlag;
}
}
public float ThrustOutput
{
get
{
return thrust;
}
}
public bool FlightFlag
{
get
{
return mouseFlightFlag;
}
}
public Vector2 ActualMouse //The real position of the mouse in screen coordinates!
{
get
{
return actualMousePosition;
}
}
public Vector2 DisplayCenter
{
get
{
return screenCenter;
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void fly()
{
//Set flight state flags based on input...
if (Input.GetAxisRaw("FlyByMouse") > 0f)
{
if (Time.time - lastFlightToggle >= 0.5f) //If 0.5 seconds have passed since the last time the player tried to toggle this, allow them to do that.
//NOTE: REVISIT AFTER IMPLEMENTING WORKING TIMER CLASS
{
if (mouseFlightFlag)
{
mouseFlightFlag = false; //If mouseFlightFlag is enabled, disable it
}
else
{
mouseFlightFlag = true; //If not then enable it.
}
mouseLookFlag = false; //Disable mouseLook when flying by mouse. That would be a cheat!
revertCameraOrientationFlag = !mouseFlightFlag; // Revert the camera back to local level only when NOT mouse flying
lastFlightToggle = Time.time;
}
}
else if (Input.GetAxisRaw("MouseLook") > 0f) //While camera pan index is held down
{
mouseLookFlag = true; //Enable camera look
revertCameraOrientationFlag = false; //Do not revert to orientation when looking around ...
if (mouseFlightFlag)
re_enableMouseFlight = true;
else
re_enableMouseFlight = false;
}
else if (mouseLookFlag && Input.GetAxisRaw("MouseLook") > 0f) //If mouseLook key is held down or released
{
mouseLookFlag = false; //Stop looking about
revertCameraOrientationFlag = true; //Return the orientation to normal
if (re_enableMouseFlight)
mouseFlightFlag = true;
else
mouseFlightFlag = false;
}
if (Input.GetAxisRaw("Cruise") > 0f) //Player should be allowed to look around while cruising!
{
if (Input.GetAxisRaw("Cruise") > 0f) //Stop cruising when reverse/slow/stop key is hit
{
readyCruiseFlag = false;
}
}
readyCruiseFlag = true;
// print("Cruising!!!");
}
public void mouseLook()
{ //Third person orbit function
cameraOrbiter.Rotate(new Vector3(-mouseReduced.normalized.y * connectorScalar * turnSpeed,
mouseReduced.normalized.x * connectorScalar * turnSpeed, 0.0f)); //TODO: MAKE THIS WORK--???
if (Input.GetAxisRaw("Mouse ScrollWheel") > 0f) //Zoom in
{
mainCamera.transform.localPosition = Vector3.Lerp(mainCamera.transform.localPosition, new Vector3(offsetVector.x, offsetVector.y, Mathf.Clamp(mainCamera.transform.localPosition.z + camerZoomStep * Time.deltaTime, -8f, -17f)), Time.deltaTime * 4f);
}
else if (Input.GetAxisRaw("Mouse ScrollWheel") < 0f) //Zoom out
{
mainCamera.transform.localPosition = Vector3.Lerp(mainCamera.transform.localPosition, new Vector3(offsetVector.x, offsetVector.y, Mathf.Clamp(mainCamera.transform.localPosition.z - camerZoomStep * Time.deltaTime, -8f, -17f)), Time.deltaTime * 4f);
}
}
void flyByMouse()
{
if (mouseLookFlag)
{
mouseLook();
}
else
{
rb.transform.Rotate(new Vector3(-Mathf.Sin(connectorAngle) * connectorScalar, Mathf.Cos(connectorAngle) * connectorScalar, keyboard.z) * turnSpeed);
mainCamera.transform.localPosition = Vector3.Lerp(mainCamera.transform.localPosition, offsetVector, Time.deltaTime * 4f);
}
}
void returnToNormal()
{
//Reorients the ship back to normal in space. This feature gives the player a way to keep their
//sense of orientation *and* allow for easier visual navigation
if (returnToForward)
{
//Slerp both the orbiter AND the ship toward the orbiter orientation to cause the ship to orient itself in the direction the camera looks.
cameraOrbiter.rotation = Quaternion.Slerp(cameraOrbiter.rotation, ship.rotation, Time.deltaTime * turnSpeed);
mainCamera.transform.localPosition = Vector3.Slerp(mainCamera.transform.localPosition, new Vector3(0f, cameraLocalHeight, -cameraLocalDistance), Time.deltaTime * 4f);
mainCamera.transform.rotation = Quaternion.Slerp(mainCamera.transform.rotation, cameraOrbiter.rotation, Time.deltaTime * 4f);
}
else //Otherwise make the ship rotate to camera orientation
{
mainCamera.transform.localPosition = Vector3.Slerp(mainCamera.transform.localPosition, new Vector3(0f, cameraLocalHeight, -cameraLocalDistance), Time.deltaTime * 4f);
}
}
void Awake()
{
screenCenter = new Vector2(Screen.width, Screen.height) / 2;
//Cursor.visible = false;
mainCamera = GameObject.Find("MainCamera").GetComponent<Camera>() as Camera;
ship = GameObject.Find("MainPlayer").GetComponent<Transform>() as Transform;
rb = GameObject.Find("MainPlayer").GetComponent<Rigidbody>() as Rigidbody;
rb.maxAngularVelocity = maximumAngularSpeed;
radialLimit = (Screen.width <= Screen.height) ? screenCenter.x * screenRatio : screenCenter.y * screenRatio; // Give squareLimit the value of the smaller screen dimension.
float dim = (Screen.width <= Screen.height) ? screenCenter.x : screenCenter.y;
print("RadialLimit=" +radialLimit + "Smaller dimension is: " + dim);
GameObject[] TEMPORARY = GameObject.FindGameObjectsWithTag("Player");
for (int c = 0; c <= TEMPORARY.Length - 1; c++)
{
targetList.Add(TEMPORARY[c]); //Update the targetList with a reference to every ship in the scene.
}
listIndex = 0;
}
// Update is called once per frame
public void Update()
{
getInput();
fly(); //Get the mouse input
controlFlight();
}
public void controlFlight()
{
if (readyCruiseFlag)
{ //Go to cruise mode
thrust = Mathf.Abs(baseThrust); //Accelerate from sitting still to normal speed while the engines charge
if (prevCruiseTimeStamp >= cruiseChargingTime) //NOTE: NEEDS A TIMER
{
thrust = cruisingSpeed; //Set cruise speed
cruisingFlag = true;
prevCruiseTimeStamp = 0f;
}
}
else
{
if (Input.GetAxisRaw("ScrollWheel") > 0f || keyboard.y > 0f) //If wanting to move forward and not cruising
{
//Increase thrust to max value
thrust = Mathf.Clamp(thrustLevel + 1f, minThrustLevel, maxThrust);
}
else if (Input.GetAxisRaw("ScrollWheel") < 0f || keyboard.y < 0f)
{
thrust = Mathf.Clamp(thrustLevel - 1f, minThrustLevel, maxThrust); //NOTE: In the FUTURE try to implement a list of set values to be interpolated from.
cruisingFlag = false;
// print("Actual speed is: " + presentThrust + "Ratio of speed is: " + thrustRatio);
}
}
if (targetList.Count > 0)
{
if (Input.GetAxisRaw("Targeting") != 0 && (Time.time - lastTargetResetTimeStamp) >= targettingResetLimit)
{ //Target selection code.
listIndex = Mathf.Clamp(listIndex + 1, 0, targetList.Count); //TargetIndex can only increment to the length.
lastTargetResetTimeStamp = Time.time;
if (listIndex == targetList.Count && targetList.Count > 0)
{ //If the index is at the limit
listIndex = 0; //Reset to zero
}
print("Setting Target on list. TargetIndex = " + listIndex + "Size of targetLIST = " + targetList.Count);
//Target.setTarget (player, targetList [targetIndex]); COMMENTED THIS OUT, FIXING THINGS
}
}
else
{
print("Setting target on NULL value");
// Target.setTarget (player, null); // COMMENTED THIS OUT, FIXING THINGS
//MouseFlightGUI **should** be adequately prepared to handle null values!
}
offsetVector = new Vector3(Mathf.Cos(connectorAngle) * connectorScalar * cameraFollowDistance, Mathf.Sin(connectorAngle) * connectorScalar * cameraFollowDistance + cameraLocalHeight, -cameraLocalDistance);
if (mouseFlightFlag)
{
flyByMouse();
}
if (mouseLookFlag)
{
mouseLook();
}
if (revertCameraOrientationFlag)
{
returnToNormal();
}
translation.z = Mathf.Lerp(playerMoveVector.z, thrust, Time.deltaTime * acceleration);
translation.x = Mathf.Lerp(translation.x, keyboard.x, Time.deltaTime * acceleration * sidestepSpeed);
speed = thrust; //Store the thrust so it can be displayed for the player
rb.transform.Translate(translation);
// shipAngularVelocity = PlayerParent.rotation - lastRotation * Time.deltaTime;
}
void getInput()
{
keyboard.x = Input.GetAxisRaw("Horizontal");
keyboard.y = Input.GetAxisRaw("Vertical");
keyboard.z = Input.GetAxisRaw("Roll");
actualMousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y) - screenCenter;
// Find mouse input relative to screen center
connectorAngle = Utilities.getAngle(actualMousePosition) * Mathf.Deg2Rad; // Get the angle from center to mouse point then convert to radians for input to trig foo's
if (actualMousePosition.magnitude > radialLimit) //If the mouse is outside of a circular area (defined by radialLimit)
{
Vector2 unitCirclePoint = new Vector2(Mathf.Cos(connectorAngle),
Mathf.Sin(connectorAngle));
mouseReduced = unitCirclePoint * radialLimit; //Scale the point out to the maximum.
}
connectorScalar = actualMousePosition.magnitude / radialLimit; //Calculate the ratio of actual length to the limit
}
}
Relevant lines in MouseFlightGUI.cs are in Displayconnectors() and Start()
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic; //Includes the List class for use
public class MouseFlightGUI : MonoBehaviour
{
public Canvas playerCanvas; //Reference to the players UI canvas
bool connectorDisplayFlag = false;
Image pointer;
public GameObject connectorParent;
public GameObject togglePrefab;
public Sprite toggleEnabledPrefab, toggleDisabledPrefab;
public Image targetReticulePrefab; //Box which goes around every ship in the area
public Text travelMode;
public Image targetBoxPrefab;
public Image pointerPrefab;
public Image ConnectorPrefab;
public Text velocityDisplay;
public float power, shift;
public float offsetX; //The end position offset of threat line's end
public int nConnectors;
List<GameObject> toggles = new List<GameObject>();
List<Transform> shipsInArea = new List<Transform>();
LineRenderer lr;
Text hllDmgReadout, shldReadout;
Image dot;
public GameObject player;
Image targetBox;
Text threatShldOut, threatHllOut;
public GameObject target;
bool displayingInfoFlag;
bool targetExists = false;
List<Image> targets = new List<Image>();
/*Decoupler variable's*/
Vector2 screenTarget; //Default/Proxy variable. Provides basic features when MouseFlight script is not in use or does no exist!
float radialLimit;
Vector2 screenCenter;
bool isCruising, isInFlight;
MouseFlight playerMouseFlight;
GunController gunController;
Camera mainCamera;
List<ConnectorStack> connectors = new List<ConnectorStack>();
//-=-=-=-=-=-=-=[Getter/Setters]-=-=-=-=-=-=-=-=-=-=-=
public Canvas Canvas
{
get
{
return playerCanvas;
}
}
public GameObject Target
{
set
{
if (value != null
&& (value != player
&& value != target
&& value.tag == "Ship"
|| value.tag == "Player")) //Make sure we don't target ourselves!
{
targetExists = true;
target = value;
print("Set target to: " + target.name);
}
}
get
{
return target;
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void hideTargetInfo() //Deactivates the target info display
{
targetBox.gameObject.SetActive(false);
// targetInfo.gameObject.SetActive();
displayingInfoFlag = false;
}
void displayTargetInfo(Vector3 targetPosition) //Displays the target box
{
targetBox.gameObject.SetActive(true);
lr.SetPosition(1, (mainCamera.WorldToScreenPoint(target.transform.position) + new Vector3(offsetX, offsetX, 1f)));
lr.gameObject.SetActive(true);
// targetInfo.gameObject.SetActive(true);
displayingInfoFlag = true;
}
void updateTargetInfo(Vector2 position)
{
targetBox.transform.position = position;
threatShldOut.text = target.GetComponent<ObjectState>().ShieldPower + " %";
threatHllOut.text = target.GetComponent<ObjectState>().HullDamage + " %";
}
/*Goes in Awake()
* playerCanvas = GameObject.Find("Canvas").GetComponent<Canvas>() as Canvas;
hllDmgReadout = GameObject.Find("ShieldCapOutput").GetComponent<Text>() as Text;
shldReadout = GameObject.Find("HullDmgOutput").GetComponent<Text>() as Text;
threatShldOut = GameObject.Find("ThreatShldCap").GetComponent<Text>() as Text;
threatHllOut = GameObject.Find("ThreatHllDmg").GetComponent<Text>() as Text;
*/
void initGunController()
{
gunController = GameObject.FindGameObjectWithTag("MainPlayer").GetComponent<GunController>();
for (int i = 0; i != gunController.guns.Count; i++) //Instantiates and initializes the gun objects on the ships hull
{
float xPos = (i < gunController.Guns.Count / 2) ? -313f * i : +313f * i; //Places each gun along the X axis. Positive for right side while negative places it on the left
Vector3 position = new Vector3(xPos, 55f, 4f);
GameObject tmp = Instantiate(togglePrefab, position, playerCanvas.transform.rotation) as GameObject;
tmp.GetComponentInChildren<Text>().text = "" + i;
tmp.GetComponentInChildren<Image>().sprite = toggleEnabledPrefab;
tmp.transform.SetParent(playerCanvas.transform);
toggles.Add(tmp);
}
}
void initMouseFlight()
{
mainCamera = playerMouseFlight.MainCam;
radialLimit = playerMouseFlight.RadialLimit;
isInFlight = playerMouseFlight.FlightFlag;
isCruising = playerMouseFlight.Cruising;
}
void Awake()
{
player = GameObject.Find("MainPlayer") as GameObject;
pointer = Instantiate(pointerPrefab, Vector3.zero, playerCanvas.transform.rotation) as Image;
pointer.transform.SetParent(connectorParent.transform);
pointer.rectTransform.localScale = Vector3.one;
targetBox = Instantiate(targetBoxPrefab, playerCanvas.transform.position, playerCanvas.transform.rotation) as Image;
// targetInfo = Instantiate(targetInfoPrefab, playerCanvas.transform.position, playerCanvas.transform.rotation) as GameObject;
lr = targetBox.gameObject.AddComponent<LineRenderer>();
lr.material = new Material(Shader.Find("UI/Default"));
lr.SetColors(Color.white, Color.red);
lr.SetWidth(1f, 1f);
lr.SetPosition(0, targetBox.rectTransform.position);
hideTargetInfo(); //Hide the threat info by default.
}
void Start()
{
if ((playerMouseFlight = ScriptCoupler.getScriptByName("MouseFlight") as MouseFlight) != null)
{
initMouseFlight();
}
else //Otherwise provide default functionality!
{
mainCamera = Camera.main;
radialLimit = (Screen.height / 2);
isCruising = false;
isInFlight = true;
}
print("Radial Limit=" + radialLimit);
if ((gunController = ScriptCoupler.getScriptByName("GunController") as GunController) != null)
{
initGunController();
}
else //Use default features. No guns!
{
///In the future this section will contain default code if GunController.cs does not exist in the scene.
}
float maximumVal = Utilities.exponential(nConnectors - 1, power, shift); // Find the highest value that exponential will return (because f in the for...next loop below this calls exponential() for every "f" and f is limited by variable connectorQuantity
for (int i = 0; i < nConnectors; i++)
{
ConnectorStack tmpConnector = connectorParent.AddComponent<ConnectorStack>();
tmpConnector.Connector = Instantiate(ConnectorPrefab).GetComponent<Image>();
tmpConnector.Connector.gameObject.SetActive(false);
float spacingRatio = Utilities.exponential(i, power, shift) / maximumVal; // This variable is used to find an appropriate exponential placement for each Connectorlink.
/*Works by multiplying the 0...+1 value given to this variable (by dividing by maximumVal) by our smallest screen dimension. Today's displays are not square. They are rectangular. We don't want
The player to be ablet to move his pointer off screen to gain a turnspeed advantage, nor move it to a corner and gain the same advantage. The diagonal distance from center to corner is further than from one side or the other. Therefore we take smallest dimension.*/
Vector2 newDimensions = (Vector2.one * spacingRatio) * tmpConnector.Connector.rectTransform.rect.width;
tmpConnector.Connector.rectTransform.SetParent(connectorParent.transform);
tmpConnector.Connector.rectTransform.rotation = playerCanvas.transform.rotation;
tmpConnector.Connector.rectTransform.position = playerCanvas.transform.position;
tmpConnector.Connector.rectTransform.sizeDelta = newDimensions;
tmpConnector.Connector.rectTransform.localScale = Vector3.one;
tmpConnector.Radius = spacingRatio * radialLimit;
tmpConnector.Index = i;
//print("Init Radius for connector: " + (i+1) + " it was: " + tmpConnector.Radius);
connectors.Add(tmpConnector);
// print("Gapscale = " + spacingRatio);
}
GameObject[] temp = GameObject.FindGameObjectsWithTag("Ship"); //Get all the ships nearby (currently in the scene)
Vector2 tempScreenPosition = new Vector2();
for (int i = 0; i < temp.Length; i++) //Add the transforms of each ship to the ShipsInArea List<>
{
shipsInArea.Add(temp[i].GetComponent<Transform>() as Transform);
tempScreenPosition = mainCamera.WorldToScreenPoint(shipsInArea[i].transform.position);
targets.Add(Instantiate(targetReticulePrefab, tempScreenPosition, playerCanvas.transform.rotation) as Image);
}
updateTargetBoxes();
}
// Update is called once per frame
void Update()
{
updateTargetBoxes();
updateGUI();
if (gunController != null)
{
updateGunController();
}
if (playerMouseFlight != null)
{
updateMouseFlight();
}
}
void updateTargetBoxes()
{
Vector2 tempScreenPosition = new Vector2();
for (int p = 0; p < targets.Count; p++)
{
//print("Updated targetbox positions.");
tempScreenPosition = mainCamera.WorldToScreenPoint(shipsInArea[p].position);
// print("Position of target reticule on screen is: " + tempScreenPosition);
targets[p].rectTransform.localPosition = tempScreenPosition;
}
}
void updateMouseFlight()
{
velocityDisplay.text = playerMouseFlight.Velocity + " m/sec";
}
void updateGunController()
{
}
void updateGUI()
{
/*
shldReadout.text = player.GetComponent<ObjectState>().HullDamage + " %";
hllDmgReadout.text = player.GetComponent<ObjectState>().ShieldPower + " %";
*/
if (targetExists)
{
Vector3 heading = target.transform.position - player.transform.position; //Get direction to target
if (Vector3.Dot(heading, mainCamera.transform.forward) > 0)
{ //If the target is in front of the camera (Z+)
screenTarget = mainCamera.WorldToScreenPoint(target.transform.position); //Find the screen position of the current target (NOT the FireGuns world
if (!displayingInfoFlag)
{ //If the targetBox has not been activated
displayTargetInfo(screenTarget);
}
updateTargetInfo(screenTarget);
}
else
{ //If it is off the screen (behind it or to the side) destroy the box and info
hideTargetInfo();
}
}
//The mode should always be displayed.
displayConnectors();
/* if (!GUIMouseFlightFlag)
{
displayConnectors(angle);
}
else
{
disableConnectors();
}
*/
}
void displayConnectors()
{
pointer.gameObject.SetActive(true);
Vector2 mouse = new Vector2(playerMouseFlight.ActualMouse.x, playerMouseFlight.ActualMouse.y);
//print("PointerPos=" + mouse);
Vector2 right = Vector2.right;
float angle;
angle = Utilities.getAngle(mouse); //Find the angle
angle *= Mathf.Sign(mouse.y); //Multiply the angle by the sign of mouse because getAngle() uses Vector2.Angle which only returns the acute angle.
for (int c = 0; c < connectors.Count; c++) //Loops through all the connectors, setting them inactive if they are outside the radius of the mouse, and moving them if they aren't.
{
if (connectors[c].Radius >= mouse.magnitude) //Disable only those connectors beyond the radius of the mouse length.
{
// print("c= "+ c + " radius=" + connectors[c].Radius + " mouse.magnitude=" + mouse.magnitude);
connectors[c].Connector.gameObject.SetActive(false);
// print("Set Connectorlink " + c + " inactive.");
}
else
{
float x, y, a;
a = angle * Mathf.Deg2Rad;
x = Mathf.Cos(a) * connectors[c].Radius;
y = Mathf.Sin(a) * connectors[c].Radius * Mathf.Sign(mouse.y);
print("x=" + x + "y=" + y +"angle=" + angle);
connectors[c].Connector.rectTransform.localPosition = new Vector3(x, y, 0);
connectors[c].Connector.rectTransform.localRotation = Quaternion.Euler(0, 0, a);
pointer.rectTransform.localPosition = new Vector3(mouse.x, mouse.y, 0f);
connectors[c].Connector.gameObject.SetActive(true);
//print("Set ACTIVE on Connectorlink: " + c);
}
// print("playerMouseFlight.ConnectorLength = " + playerMouseFlight.ConnectorLength + " and ConnectorGap is = " + ConnectorGap[c]);
}
}
}
Video: