public void ApplyExternalForce(Vector3 force, PlaneComponent planeComponent = PlaneComponent.All, bool freshParallel = false) { Vector3 relevantForce = force; switch (planeComponent) { case PlaneComponent.Plane: relevantForce = OnPlane(force); break; case PlaneComponent.Normal: relevantForce = OnPlaneNormal(force); break; } // When using fresh parallel, remove all other motion in the force direction. if (freshParallel) { var forceDirection = force.normalized; externalForce -= Vector3.Project(externalForce, forceDirection); body.velocity -= Vector3.Project(body.velocity, forceDirection); } externalForce += relevantForce; }
void OnCollisionEnter(Collision hit) { PlaneComponent pC = hit.collider.gameObject.GetComponent <PlaneComponent>(); if (pC != null) { pC.DoDamage(1000); } }
public void Shoot() { if (HasAmmo && plane != null) { HasAmmo = false; Invoke("Reload", 0.25f); FireLine(); shotInProgress = true; Invoke("ResetLine", 0.125f); audioSource.Play(); Ray r = new Ray(transform.position, plane.transform.forward * 1500.0f); RaycastHit[] hits = Physics.RaycastAll(r, 1500); GameObject closestObj = null; float distance = 1600.0f; hitPos = plane.transform.forward * 500.0f + transform.position; for (int i = 0; i < hits.Length; i++) { PlaneComponent pC = hits[i].collider.gameObject.GetComponent <PlaneComponent>(); if (pC != null) { if (!pC.IsSamePlane(plane)) { float compare = Vector3.Distance(transform.position, hits[i].collider.gameObject.transform.position); if (compare < distance) { distance = compare; closestObj = hits[i].collider.gameObject; hitPos = hits[i].point; } } } else { float compare = Vector3.Distance(transform.position, hits[i].collider.gameObject.transform.position); if (compare < distance) { distance = compare; closestObj = hits[i].collider.gameObject; hitPos = hits[i].point; } } } if (closestObj != null) { PlaneComponent pC = closestObj.GetComponent <PlaneComponent>(); if (pC != null) { GameObject g = Instantiate(bulletHolePrefab, hitPos, transform.rotation); g.transform.LookAt(transform.position, Vector3.Cross(hitPos, transform.position)); g.transform.SetParent(closestObj.transform); int damage = 150 - (int)(Mathf.Floor(125.0f * (distance / 1500))); pC.SetLastHit(plane.GetPlayerName()); pC.DoDamage(damage); } } } }
public override void InitializeComponents() { var location = Assembly.GetExecutingAssembly().Location; var shadersPath = Path.GetDirectoryName(location) + "\\Shaders\\ShadowMapLightingShaders.hlsl"; grid = new GridComponentTextured(GameDevice); var texturePath = Path.GetDirectoryName(location) + "\\Textures\\marble_texture2.jpg"; grid.InitializeResources(texturePath, new BlackPlastic(), shadersPath, shadersPath, InputElements.VertexPosNormTex); grid.Translation = new Vector3(-grid.Lenght / 2f, 0f, -grid.Lenght / 2f); cow = new ObjModelComponent(GameDevice); texturePath = Path.GetDirectoryName(location) + "\\Textures\\cow_texture.jpg"; var filePath = Path.GetDirectoryName(location) + "\\Meshes\\cow.obj"; cow.InitializeResources(texturePath, new Silver(), shadersPath, shadersPath, InputElements.VertexPosNormTex, filePath); cow.Scaling = new Vector3(0.01f, 0.01f, 0.01f); texturePath = Path.GetDirectoryName(location) + "\\Textures\\marble_texture2.jpg"; string[] cubetexturesPath = new string[] { Path.GetDirectoryName(location) + "\\Textures\\SkyText\\miramar_ft.bmp", Path.GetDirectoryName(location) + "\\Textures\\SkyText\\miramar_bk.bmp", Path.GetDirectoryName(location) + "\\Textures\\SkyText\\miramar_dn.bmp", Path.GetDirectoryName(location) + "\\Textures\\SkyText\\miramar_up.bmp", Path.GetDirectoryName(location) + "\\Textures\\SkyText\\miramar_lf.bmp", Path.GetDirectoryName(location) + "\\Textures\\SkyText\\miramar_rt.bmp", }; skySphere = new FBXComponent(GameDevice); filePath = Path.GetDirectoryName(location) + "\\Meshes\\skySphere2.fbx"; skySphere.InitializeResources(cubetexturesPath, shadersPath, shadersPath, InputElements.VertexPosNormTex, filePath); skySphere.isLighten = false; // skySphere.InitializeResources(texturePath, new Silver(), shadersPath, shadersPath, InputElements.VertexPosNormTex, filePath); skySphere.Scaling = new Vector3(0.1f, 0.1f, 0.1f); plane = new PlaneComponent(GameDevice); PlaneTexture = worldPositionMap; plane.InitializeResources(shadowMapResourseView, new Silver(), shadersPath, shadersPath, InputElements.VertexPosNormTex); plane.Rotation = Matrix.RotationYawPitchRoll(MathUtil.DegreesToRadians(0f), MathUtil.DegreesToRadians(-90f), MathUtil.DegreesToRadians(0f)); plane.Translation = new Vector3(10f, 10f, 0f); consoleComponent = new ConsoleComponent(); consoleComponent.Initialize(this); LuaManager = new LuaScriptManager(this); }