I’m creating a homeworld style movement system and having a ton of difficulty getting unity to create a plane struct at the proper level of worldspace.
I want to create an XZ plane that is always flat (same as XZ in world) but want it to stay at the Y elevation of the object that I’m creating to calculate distance and direction from.
Basically, I want to create a struct plane to draw a disc/circle on and to use to intersect with a screen raycast to obtain a direction and distance from the ship (origin).
Here’s my existing code layout.
using UnityEngine;
using System.Collections;
public class UnitMovement : MonoBehaviour {
static GameObject objectNameInfo;
Vector3 inPoint;
void start()
{
objectNameInfo = RTSControlSelect.objectName;
inPoint = objectNameInfo.transform.position;
}
void update()
{
if (Input.GetKeyDown(KeyCode.M))
{
Plane.SetNormalAndPosition (vector3.up, vector3.inPoint);
}
rotateToPoint();
moveToPoint();
}
void rotateToPoint()
{
}
void moveToPoint()
{
}
}
I know I need to convert the transform.position that I’m passing into a vector3 or something in order to do this. How can I just get the Y value from the transform.position and pass it to the Plane.SetNormalAndPosition?
Second, how to I generate the struct in the first place? How do I give it a name or get data from it?
Lastly, how do I get the point of intersection with the raycast I plan to do or how do I store the distance and direction to the point of intersection?
On a side note, I plan to add a “leftshift” key modifier that moves the point of intersection using translate(vector3.up) with mouse Y input. I also want to allow this script to have a selected ship get the distance and direction to an object that is right clicked.
PLEASE HELP THIS POOR FRUSTRATED SOUL!!! BTW, I don’t code in JavaScript. All C#.
Okay so this all works... But I want to draw a line from inPoint to hitPoint. I've tried to pass the data of objectNameInfo.transform.position ("= RTSControlSelect.objectName") to inPoint. However, no matter how I seem to try and pass the data, it always gives me a null reference. I have an RTSCameraControl script that inherits the same data from RTSControlSelect in the same way... Why won't it work here?
– thundaxI don't really understand your question. Can you tell me the exact line of code? I'm not sure what you're trying to do, but if I see the code I might be able to work it out.
– syclamoth