So how do I flip a entity? I have the BaseEntity defined but I do not know how to flip it itself? I know there is something like: Quaternion that handles angles but i'm not sure how it works. Any advice(Didn't see any plugins that use this)?
For example I would want to flip that entity(then raise it but I can do that via editing the vector3 location.
Code:[ChatCommand("flipturret")] void cmdFlipTurret(BasePlayer player) { inputState = serverinput.GetValue(player) as InputState; Ray ray = new Ray(player.eyes.position, Quaternion.Euler(inputState.current.aimAngles) * Vector3.forward); BaseEntity flipObject = FindTurret(ray, 5f); }
Flipping an object?
Discussion in 'Rust Development' started by DylanSMR, Aug 4, 2016.
-
Right so I got that working. Now I get the problem where if I raise a turret more than foundation height it automatically destroys. Is there a way to disable that(stability issue I think)
-
Not sure if this is of help in your case but this lets you get ground level
Code:static Vector3 getGroundPosition(Vector3 sourcePos) // credit Wulf & Nogrod { RaycastHit hit; if (Physics.Raycast(sourcePos, Vector3.down, out hit, GROUND_MASKS)) { sourcePos.y = hit.point.y; } sourcePos.y = Mathf.Max(sourcePos.y, TerrainMeta.HeightMap.GetHeight(sourcePos)); return sourcePos; } -
I got it finished. Im just awaiting approval
. Thanks for that though I might have to use it. -
A very nice client of mine pointed out that this method will sometimes return a V3 that is in mid-air. It isn't entirely accurate as it will detect sphere and mesh colliders so the return can be on top of say the Tool Cupboard build range or a ZoneManager zone. I wrote a new method this morning that I will be updating my plugins with to fix the issue, others may also find use in it.
Sorry for the OTCode:Vector3 GetGroundPosition(Vector3 sourcePos) { var hitInfo = RayPosition(sourcePos); var success = ProcessRay(hitInfo); if (success is Vector3) { var pos = GetGroundPosition(new Vector3(sourcePos.x, ((Vector3)success).y, sourcePos.z)); return pos; } else { sourcePos.y = Mathf.Max((float)success, TerrainMeta.HeightMap.GetHeight(sourcePos)); return sourcePos; } } private object ProcessRay(RaycastHit hitInfo) { if (hitInfo.collider != null) { if (hitInfo.GetEntity() != null) { return hitInfo.point.y; } if (hitInfo.collider?.GetComponentInParent<SphereCollider>()) { return hitInfo.collider.transform.position + new Vector3(0, -1, 0); } if (hitInfo.collider?.GetComponentInParent<MeshCollider>()) { if (hitInfo.collider?.GetComponentInParent<MeshCollider>().name == "areaTrigger") return hitInfo.collider.transform.position + new Vector3(0, -1, 0); } } return hitInfo.point.y; } RaycastHit RayPosition(Vector3 sourcePos) { RaycastHit hitInfo; Physics.Raycast(sourcePos, Vector3.down, out hitInfo, LayerMask.GetMask("Terrain", "World", "Construction")); return hitInfo; }
