Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

Erarnitox

Member
  • Content Count

    349
  • Joined

  • Last visited

  • Days Won

    20

Everything posted by Erarnitox

  1. yeah its actually very simple to do but here you go: using UnityEngine; public class Peek : MonoBehaviour { public Transform cam; public Transform cam2; private float nextPos; private float nextPos2; private float dampVelocity; private float dampVelocity2; void Update() { float newPos = Mathf.SmoothDamp(cam.transform.localPosition.x, nextPos, ref this.dampVelocity, 0.2f); float newPos2 = Mathf.SmoothDamp(cam.transform.localPosition.y, nextPos2, ref this.dampVelocity2, 0.2f); float newPos3 = Mathf.SmoothDamp(cam2.transform.localPosition.x, nextPos, ref this.dampVelocity, 0.2f); float newPos4 = Mathf.SmoothDamp(cam2.transform.localPosition.y, nextPos2, ref this.dampVelocity2, 0.2f); cam.transform.localPosition = new Vector3(newPos, newPos2, cam.transform.localPosition.z); cam2.transform.localPosition = new Vector3(newPos3, newPos4, cam2.transform.localPosition.z); if (Input.GetKey("x")) { nextPos = 0.7f; nextPos2 = 0.0f; } else if (Input.GetKey("z")) { nextPos = -0.7f; nextPos2 = 0.0f; } else if (Input.GetKey("c")) { nextPos = 0.0f; nextPos2 = 0.0f; } else { nextPos = 0.0f; nextPos2 = 0.0f; } } /* [RPC] //Rpcs are not supported anymore since raknet got removed from unity use UNET or some other networking soulution (TNet is like raknet if you want a quick convert) void Test() {} */ } by the way i would not use the code the way it is it looks hacked together and will be pretty inperformant. Also there are no Remote procedure calls like that anymore, if you want to have networked methods you have to do it differently, wrote a quick comment on the side.
  2. hey there i made a small script and it should only transition between cameras when the room was entered. The first 2-3 times it always works but then it wouldnt work and work sometimes again. here is a video of the problem: and here is the script just without the debug output (debug log in video gets called on trigger enter) using UnityEngine; public class CameraMove : MonoBehaviour { private Transform mainCamera; [Header("Where should the Camera be placed in the Room:")] public Transform cameraPosition; private Vector3 startPos; private Quaternion startRot; private float completion; private bool lerp = false; void Start() { mainCamera = GameObject.FindWithTag("MainCamera").transform; } void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { startPos = mainCamera.position; startRot = mainCamera.rotation; completion = 0; lerp = true; } } private void Update() { if (lerp) { if (Vector3.Distance(cameraPosition.position, startPos) > 0.1f) { completion += Time.deltaTime; mainCamera.position = Vector3.Lerp(startPos, cameraPosition.position, completion); mainCamera.rotation = Quaternion.Lerp(startRot, cameraPosition.rotation, completion); } else { lerp = false; } } } } i feel stupid ^^ should be something simple im missing. The script gets assigned to each room, both of them have a box collider which is marked as trigger. Thanks for the help Edit: I have fixed it! If you want you can use the code. Here is the fixed Version: using UnityEngine; public class CameraMove : MonoBehaviour { public static Transform mainCamera; [Header("Where should the Camera be placed in the Room:")] public Transform cameraPosition; private Vector3 startPos; private Quaternion startRot; private float completion; private bool lerp = false; void Start() { mainCamera = GameObject.FindWithTag("MainCamera").transform; } void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { startPos = mainCamera.position; startRot = mainCamera.rotation; completion = 0; lerp = true; } } private void Update() { if (lerp) { if (Vector3.Distance(cameraPosition.position, mainCamera.position) > 0.1f) { completion += Time.deltaTime; mainCamera.position = Vector3.Lerp(startPos, cameraPosition.position, completion); mainCamera.rotation = Quaternion.Lerp(startRot, cameraPosition.rotation, completion); } else { lerp = false; } } } } }
  3. another idea would be to disable the collider and enabling a trigegr object infront of the player that takes case of collisions or a boxcast
  4. yeah, but i dont think that was the problem ... but i have no idea what might be
  5. okay... well i dont think it will change much but here are some last simplifications to slim down room for error: using UnityEngine; public class DamageIndicator : MonoBehaviour { public Texture damageIndicatorTexture; //Private private Vector2 pivotPoint; private float alpha = 0.0f; private float rotationOffset; private Vector3 attackDirection; void OnGUI() { if(alpha > 0){ GUI.color = new Color (1.0f, 1.0f, 1.0f, alpha); Vector2 vector = new Vector2 (((Screen.width / 2) - (damageIndicatorTexture.width / 2)), (Screen.height / 2)); GUIUtility.RotateAroundPivot (rotationOffset, new Vector2 ((Screen.width / 2), (Screen.height / 4))); GUI.DrawTexture (new Rect (vector.x, vector.y, damageIndicatorTexture.width, damageIndicatorTexture.height), damageIndicatorTexture); } } public void AttackFrom(Vector3 dir) { attackDirection = dir; alpha = 3f; } void Update() { if (this.alpha > 0) { this.alpha -= Time.deltaTime; this.UpdateDirection(); } } void UpdateDirection() { if(alpha > 0){ Vector3 rhs = attackDirection - transform.position; rhs.y = 0; rhs.Normalize(); Vector3 forward; forward = transform.forward; float GetPos = Vector3.Dot(forward, rhs); if (Vector3.Cross(forward, rhs).y > 0){ rotationOffset = (1f - GetPos) * 90; } else{ rotationOffset = (1f - GetPos) * -90; } } } }
  6. thats strange tbh. does it get called from somewhre else as well maybe? i really dont know at this point but it pretty confident that the code is okay edit: this is a pretty dumb idea but .... maybe disable the minimap? edit2: most likely its not the minimap but probably sth. real simple... try to disable as much from the scene as possible to make a "clean" environment for testing... maybe you stumble over the thing that causes it?
  7. made some small changes again and now its working fine for me depending on your texture you might want to change the offset variable to something else like Screen.height/4 instead of /2 but that does look better for me i saw u used /4 in your code thats why i did mention that so anyways here is the code: using UnityEngine; public class DamageIndicator : MonoBehaviour { [HideInInspector] public Vector3 attackDirection; public Texture damageIndicatorTexture; //Private private Vector2 pivotPoint; private float alpha = 0.0f; private float rotationOffset; void OnGUI() { if (alpha > 0) { GUI.color = new Color(1.0f, 1.0f, 1.0f, alpha); float offset = Screen.height / 2; Vector2 vector = new Vector2(((Screen.width / 2) - (damageIndicatorTexture.width / 2)), (Screen.height / 2) - offset); GUIUtility.RotateAroundPivot(rotationOffset, new Vector2((Screen.width / 2), (Screen.height / 2))); GUI.DrawTexture(new Rect(vector.x, vector.y, damageIndicatorTexture.width, damageIndicatorTexture.height), damageIndicatorTexture); } } public void AttackFrom(Vector3 dir) { attackDirection = dir; alpha = 3f; } void Update() { if (this.alpha > 0) { this.alpha -= Time.deltaTime; this.UpdateDirection(); } } void UpdateDirection() { if (alpha > 0) { Vector3 rhs = attackDirection - transform.position; rhs.y = 0; rhs.Normalize(); Vector3 forward; if (Camera.main != null) { forward = Camera.main.transform.forward; } else { if (Camera.current != null) { forward = Camera.current.transform.forward; } else { forward = transform.forward; } } float GetPos = Vector3.Dot(forward, rhs); if (Vector3.Cross(forward, rhs).y > 0) { rotationOffset = (1f - GetPos) * 90; } else { rotationOffset = (1f - GetPos) * -90; } } } } I did also write a small script to test it: using UnityEngine; public class AttackFrom : MonoBehaviour { public DamageIndicator script; public GameObject target; void Update() { script.AttackFrom(target.transform.position); } } the second script is only for debugging but it helped me to figure out the offset that looks right. here a clip of it in action:
  8. if its facing a different direction but i think this is unlikely
  9. well i did some cleaning up to undestand the code better but i hnestly think everything should be fine with your code! i made some small simplifications, maybe give it a try? But it should do the same thing.... also im pretty positive the code should work! I went trough it step by step all the calculations should be right Still here is my version of the script: using UnityEngine; using System.Collections; public class DamageIndicator : MonoBehaviour { [HideInInspector] public Vector3 attackDirection; public Texture damageIndicatorTexture; //Private private Vector2 pivotPoint; private float alpha = 0.0f; private float rotationOffset; void OnGUI() { if(alpha > 0){ GUI.color = new Color (1.0f, 1.0f, 1.0f, alpha); Vector2 vector = new Vector2 (((Screen.width / 2) - (damageIndicatorTexture.width / 2)), (Screen.height / 2)); GUIUtility.RotateAroundPivot (rotationOffset, new Vector2 ((Screen.width / 2), (Screen.height / 2))); GUI.DrawTexture (new Rect (vector.x, vector.y, damageIndicatorTexture.width, damageIndicatorTexture.height), damageIndicatorTexture); } } public void AttackFrom(Vector3 dir) { attackDirection = dir; alpha = 3f; } void Update() { if (this.alpha > 0) { this.alpha -= Time.deltaTime; this.UpdateDirection(); } } void UpdateDirection() { if(alpha > 0){ Vector3 rhs = attackDirection - transform.position; rhs.y = 0; rhs.Normalize(); Vector3 forward; if (Camera.main != null){ forward = Camera.main.transform.forward; } else { if (Camera.current != null){ forward = Camera.current.transform.forward; } else{ forward = transform.forward; } } float GetPos = Vector3.Dot(forward, rhs); if (Vector3.Cross(forward, rhs).y > 0){ rotationOffset = (1f - GetPos) * 90; } else{ rotationOffset = (1f - GetPos) * -90; } } } } You could check if the Main Camera is really the only active camera in the scene Also you could check with a static position like a cube if the indicator alsways points to it (maybe there is a problem with the bullet/ turret position) well good luck with it and hopefully i solved it by accident haha ^^ Edit: wait... i messed sth. up was testing it ^^ haha
  10. give me one second ill check something
  11. if you put all optics under one child you can completely disable the optics object and enable it again so all childern get disabled as well with it.
  12. using UnityEngine; using System.Collections; public class DamageIndicator : MonoBehaviour { /// <summary> /// Attack from direction /// </summary> [HideInInspector] public Vector3 attackDirection; /// <summary> /// time reach for fade arrow /// </summary> public float FadeTime = 3; public Texture damageIndicatorTexture; public Color ArrowColor = new Color(0.85f, 0, 0); /// <summary> /// the transform root of player /// </summary> public GameObject target; //Private public Vector2 pivotPoint; public float alpha = 0.0f; public float offset = 350f; public float rotationOffset; /// <summary> /// /// </summary> void OnGUI() { if (this.alpha > 0) { this.offset = Screen.height / 4; GUI.color = new Color(ArrowColor.r, ArrowColor.g, ArrowColor.b, this.alpha); Vector2 vector = new Vector2(((Screen.width / 2) - (this.damageIndicatorTexture.width / 2)), (Screen.height / 2) - this.offset); this.pivotPoint = new Vector2((Screen.width / 2), (Screen.height / 2)); GUIUtility.RotateAroundPivot(this.rotationOffset, this.pivotPoint); GUI.DrawTexture(new Rect(vector.x, vector.y, this.damageIndicatorTexture.width, this.damageIndicatorTexture.height), this.damageIndicatorTexture); } } /// <summary> /// Use this to send a new direction of attack /// </summary> /// <param name="dir">postion of attacker</param> public void AttackFrom(Vector3 dir) { //target = this.transform ; this.attackDirection = dir; this.alpha = 3f; } /// <summary> /// if this is visible Update position /// </summary> void Update() { // Player Clone integration Start if (target == null) if (GameObject.Find("Player")) target = GameObject.Find("Player"); // player clone integration end if (this.alpha > 0) { this.alpha -= Time.deltaTime; this.UpdateDirection(); } } /// <summary> /// update direction as the arrow shows /// </summary> void UpdateDirection() { Vector3 rhs = this.attackDirection - this.target.transform.position; rhs.y = 0; rhs.Normalize(); Vector3 forward; if (Camera.main != null) { forward = Camera.main.transform.forward; } else { if (Camera.current != null) { forward = Camera.current.transform.forward; } else { forward = this.transform.forward; } } float GetPos = Vector3.Dot(forward, rhs); if (Vector3.Cross(forward, rhs).y < 0) { this.rotationOffset = (1f - GetPos) * 90; } else { this.rotationOffset = (1f - GetPos) * -90; } } } i just flipped the left/right code part .... maybe that works ... from your video it looks like it might. Just a guess but maybe you somewhere flipped the argument and thus the plane the 2 vectors span is upside down. I will check that later if it works to fix that properly ^^ but use this script first to see if it fixes the problem
  13. tbh. this looks right to me. Might be i overlooked sth. tho. does your Damage Indecator texture point upwards? maybe try to call it from a debug script to test various positions? also try to set adjust manually to see if it starts out at the right position and rotates the way you expect. ... the update position method itself looks from what i see like it should (might have overlooked sth.)
  14. so yeah thats why in weapon manager disable the text right before you switch to the next weapon and after you disabled the old one
  15. from where does this method get called and also when does it get called? calling it once after every weapon switch should fix it, right? also where is the component placed? if its on the no weapon object it cant run once the object is deactivated
  16. double click it? ^^ looks like a syntax error so yeah a missing ; or sth. like that .... just check out whats missing i dont know what code is at that line
  17. yeah is solveable should work if you do sth. like this: // ADDON JC LEON ONLY PICKUP START public void CheckObjectForPickupOnly() { if(!weaponManager.disarmed){ _canPickup = false; InteractUIPickup.SetActive(false); StaticCross.SetActive(false); return; } RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, RayDistance, layerMask.value)) { Pickable pickable = hit.collider.GetComponent<Pickable>(); if (hit.rigidbody && !hit.rigidbody.isKinematic /*&& hit.rigidbody.mass <= maxMass*/ && pickable.isPickableOnly) { InteractUIPickup.SetActive(true); _canPickup = true; StaticCross.SetActive(true); } else { _canPickup = false; InteractUIPickup.SetActive(false); StaticCross.SetActive(false); } } else if (_canPickup == true) { _canPickup = false; InteractUIPickup.SetActive(false); StaticCross.SetActive(false); } } // ADDON JCLEON OLY PIVKUP END hope that works not too sure tho.
  18. ah i see lol ^^ i think it got stuck in the collider of the player? cant rembre exactly but there was a way you can set up masks for the collision, just know that if you do that you will also be able to walk through it. But this is the only thing that comes to my mind... or well you could ignore player collisions until you hit something other than the player and than enable them again... But really i would just set it to where it works fine and dont worry too much about it, just keep it in mind for big objects so you can set teir pivot accordingly etc. Edit: after watching again it lookes like sth. else is going on since the grab time increases but i honestly cant tell you why im sry. Might be cheking your script again later... maybe some conditon where you have to hit the player or other collider causes this.
  19. but there are values of adjust that work? most likely nothing to do with adjust but rather disabeling something when you pick up that doesnt get enabled again when you drop or sth. like that. Im actually sorry i couldnt spot sth. at first sight... also im not quite positive if i got you correctly ... i know its annoying but a video of the issue really helps me understand things also i have sth. to do right now but will get back later
  20. yes, it should but i think this gets optimized at compile time to what i wrote anyways so its the same just easier to read when you leave that away
  21. 1) create a new script and add it to the Player Obeject and/or Prefab in scene 2) write this into the script: public class Helper : MonoBehaviour{ public GrabObjects grabObjects; } 3) drag n drop "No Weapon" into the the grabobjects slot of that script 4) the new Pickable Script should look like this: using UnityEngine; using System.Collections; using System.Collections.Generic; using EasySurvivalScripts; public class Pickable : MonoBehaviour { //[Header("JC LEON Other Scripts References Integrations")] private GrabObjects grabObjects; private TextAnimator textAnimator; [SerializeField] private string MyMessage; [Header("JC LEON Only Pickable Object Integration")] [Tooltip("thick to set object only pPickable and not Examinable")] public bool isPickableOnly;//ADDED JC LEON only pickup private void Start() { grabObjects = GameObject.FindWithTag("Player").GetComponent<Helper>().grabObjects; textAnimator = FindObjectOfType<TextAnimator>(); } public void ShowMessage() { textAnimator.Show(MyMessage); } void OnTriggerEnter(Collider otherCollider) { //If that GameObject is either static, without a rigidbody, or with a rigidbody that is also kinematic (in other words, that GameObject is not supposed to move)... //Then we call the ObjectCheck method. if (grabObjects.isGrabbing && grabObjects.GrabTime != 0.0f) { if (otherCollider.GetComponent<Collider>().gameObject.isStatic) { grabObjects.GetComponent<GrabObjects>().Drop(); Debug.Log("ciao"); } else if (otherCollider.GetComponent<Collider>().gameObject.GetComponent<Rigidbody>() == null) { grabObjects.Drop(); Debug.Log("ciao"); } else if (otherCollider.GetComponent<Collider>().gameObject.GetComponent<Rigidbody>()) { grabObjects.Drop(); Debug.Log("ciao"); } else if (otherCollider.GetComponent<Collider>().gameObject.GetComponent<Rigidbody>().isKinematic == true) { grabObjects.Drop(); Debug.Log("ciao"); } } } } 5) test it ... not sure if that will work but i think that was the problem 6) mark this as best answer (if it works, else call me stupid or sth. )
  22. ah damn i fucked that up ^^ its on the noweapon not on the player right? So do you have any component that accesses that game object directly on the player? If not it might actually be the best to create one to be able to access it. like: public class Helper : MonoBehaviour{ public GrabObjects grabLogic; } sth. lke that and drop it on the player, then change the line in Start() where it assigns grabObjects to this: grabObjects =GameObject.FindWithTag("Player").GetComponent<Helper>().grabLogic; i know this is not very elegant but should do the trick if not ill download the kit and try to fix it there edit: make sure that you asign the NoWeapon to grabLogic (unity will grab the correct component automatically) edit2: idk why this is all red this is not on purpose but im on mobile and too lazy to change color ^^ no meaning behind that
  23. using UnityEngine; using System.Collections; using System.Collections.Generic; using EasySurvivalScripts; public class Pickable : MonoBehaviour { //[Header("JC LEON Other Scripts References Integrations")] private GrabObjects grabObjects; private TextAnimator textAnimator; [SerializeField] private string MyMessage; [Header("JC LEON Only Pickable Object Integration")] [Tooltip("thick to set object only pPickable and not Examinable")] public bool isPickableOnly;//ADDED JC LEON only pickup private void Start() { grabObjects = GameObject.FindWithTag("Player").GetComponent<GrabObjects>(); textAnimator = FindObjectOfType<TextAnimator>(); } public void ShowMessage() { textAnimator.Show(MyMessage); } void OnTriggerEnter(Collider otherCollider) { //If that GameObject is either static, without a rigidbody, or with a rigidbody that is also kinematic (in other words, that GameObject is not supposed to move)... //Then we call the ObjectCheck method. if (grabObjects.isGrabbing && grabObjects.GrabTime != 0.0f) { if (otherCollider.GetComponent<Collider>().gameObject.isStatic) { grabObjects.GetComponent<GrabObjects>().Drop(); Debug.Log("ciao"); } else if (otherCollider.GetComponent<Collider>().gameObject.GetComponent<Rigidbody>() == null) { grabObjects.Drop(); Debug.Log("ciao"); } else if (otherCollider.GetComponent<Collider>().gameObject.GetComponent<Rigidbody>()) { grabObjects.Drop(); Debug.Log("ciao"); } else if (otherCollider.GetComponent<Collider>().gameObject.GetComponent<Rigidbody>().isKinematic == true) { grabObjects.Drop(); Debug.Log("ciao"); } } } } yeah, i think i got it, try this! I hope i dednt mess shit up since i edited that in the browser ^^
  24. dont quite get it or how this can happen but i think that creating a prefab is not really the way to go here, check why it even got dereferenced?
  25. Erarnitox

    Long time

    not sure about that i really think @OcularCash is a dude, i think he posted his real name some times as well
×
×
  • Create New...