Jump to content

Creating an object is causing craft to explode


Recommended Posts

I'm trying to create a pointer to be used to adjust a camera position.  My problem is that when the pointer happens to be over a part, there are collisions,  Here is the code:

public static class UI
{
	public static GameObject CreatePrimitive(PrimitiveType type, Color color, Vector3 scale, bool isActive, string name = "", string shader = "Diffuse")
	{
		GameObject obj = GameObject.CreatePrimitive(type);

		var renderer = obj.GetComponent<Renderer>();

		renderer.material.color = color;
		obj.transform.localScale = scale;
		obj.SetActive(isActive);
		obj.name = name;
		renderer.material.shader = Shader.Find(shader);
		obj.layer = 10;
		return obj;
	}
	public static Color GetColorFromRgb(byte r, byte g, byte b, byte a = 255)
	{
		var c = new Color(r / 255f, g / 255f, b / 255f, a / 255f);
		return c;
	}
}

      
orientationPointer = UI.CreatePrimitive(PrimitiveType.Cylinder, orientColor, new Vector3(0.025f, 0.4f, 0.025f), false, "Orientation Pointer", TransShader);
orientationPointer.SetActive(false);
          
orientationPointer.transform.position = dcm._camera._moduleDockingNodeGameObject.transform.position;

orientationPointer.transform.rotation = dcm._camera._moduleDockingNodeGameObject.transform.rotation;
Vector3 v3 = dcm.cameraPosition;

orientationPointer.transform.position += dcm._camera._moduleDockingNodeGameObject.transform.rotation * v3;
orientationPointer.transform.rotation = dcm.vessel.transform.rotation; ;
orientationPointer.transform.rotation *= Quaternion.LookRotation(dcm.cameraUp, dcm.cameraForward);

orientationPointer.SetActive(showOrientationPointer);

I'm guessing that the object being created somehow has colliders, and when set active they collide with the craft.

How can I prevent this from happening?

Just an FYI, the code is mostly taken from the NodeHelper mod.

 

I'll add that when I first created it, the location was not correct and I saw the cylinder to the side, when I fixed the location, the vessel exploded.

Thanks in advance

Edited by linuxgurugamer
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...