|
Post by Jader on Aug 24, 2017 21:42:29 GMT
Hi,
I'm working in a mobile game, and i need to reduce number of buttons in screen and simplify the gameplay.
I think that an good solution is the auto activate the LockOn when player get close to the enemy.
I searched and tried multiple ways, without success.
If anyone can help me...
Thanks
Ps. Sorry for my english =)
|
|
|
Post by dendiee on Aug 24, 2017 23:34:51 GMT
Hi, I'm working in a mobile game, and i need to reduce number of buttons in screen and simplify the gameplay. I think that an good solution is the auto activate the LockOn when player get close to the enemy. I searched and tried multiple ways, without success. If anyone can help me... Thanks Ps. Sorry for my english =) well there are many ways of doing this. the simplest way (not the best) is make a invisiblie collider in the range u wish. then under OnTriggerEnter you could simulate pressing "tab" or whatever the button is with u. You will probably need to check if he is focusing or not , in case a second enemy is also near. make sure the range is not further as the lockon range. summary: OnTriggerEnter: check if yiu are locked on or not , if not ,lock on. OnTriggerStay: check if u are locked on or not, if not update tatgets and move to next if there is any. OnTriggerExit: disable lockon.
|
|
|
Post by Jader on Aug 24, 2017 23:57:09 GMT
Hi, I'm working in a mobile game, and i need to reduce number of buttons in screen and simplify the gameplay. I think that an good solution is the auto activate the LockOn when player get close to the enemy. I searched and tried multiple ways, without success. If anyone can help me... Thanks Ps. Sorry for my english =) well there are many ways of doing this. the simplest way (not the best) is make a invisiblie collider in the range u wish. then under OnTriggerEnter you could simulate pressing "tab" or whatever the button is with u. You will probably need to check if he is focusing or not , in case a second enemy is also near. make sure the range is not further as the lockon range. summary: OnTriggerEnter: check if yiu are locked on or not , if not ,lock on. OnTriggerStay: check if u are locked on or not, if not update tatgets and move to next if there is any. OnTriggerExit: disable lockon. It's was my initial idea, but i don't know how to call the function to enable the LockOn Thats my test code using UnityEngine; using System.Collections; using UnityStandardAssets.CrossPlatformInput; using Invector.ItemManager; using Invector.EventSystems; using System; public class AutoLockOn : MonoBehaviour { public v3rdPersonCamera vcam; public void Lock (){ vcam.UpdateLockOn (true); } public void UnLock (){ vcam.UpdateLockOn (false); } }
|
|
|
Post by Jader on Aug 25, 2017 0:22:47 GMT
I can't find the function to enable or disable the LockOn.
v3rdPersonCamera.UpdateLockOn (true); Only affect the crosshair. v3rdPersonCamera.lockOn = true; lockOn is not a bool;
|
|
|
Post by Jader on Aug 25, 2017 1:11:50 GMT
almost there...
Based in a dendiee ideia. But not disable LockOn when trigger exit. What is wrong?
using UnityEngine; using System.Collections; using UnityStandardAssets.CrossPlatformInput; using Invector;
public class AutoLockOn : MonoBehaviour {
public bool Teste;
void Update (){
Teste = vLockOnTarget._inLockOn
}
void OnTriggerEnter (Collider collider){ if (collider.gameObject.tag == "Enemy") { if (!vLockOnTarget._inLockOn) { // locked = true; CrossPlatformInputManager.SetButtonDown ("RightStickClick"); Debug.Log ("Enter");
} }
}
void OnTriggerExit (Collider collider){
if (collider.gameObject.tag == "Enemy") {
if (vLockOnTarget._inLockOn) {
CrossPlatformInputManager.SetButtonDown ("RightStickClick"); Debug.Log ("Exit");
} }
}
void OnTriggerStay (Collider collider){
if (collider.gameObject.tag == "Enemy") {
if (!vLockOnTarget._inLockOn) {
CrossPlatformInputManager.SetButtonDown ("RightStickClick"); Debug.Log ("Stay");
} }
}
}
|
|
|
Post by dendiee on Aug 25, 2017 9:13:44 GMT
almost there... Based in a dendiee ideia. But not disable LockOn when trigger exit. What is wrong? using UnityEngine; using System.Collections; using UnityStandardAssets.CrossPlatformInput; using Invector; public class AutoLockOn : MonoBehaviour { public bool Teste; void Update (){ Teste = vLockOnTarget._inLockOn } void OnTriggerEnter (Collider collider){ if (collider.gameObject.tag == "Enemy") { if (!vLockOnTarget._inLockOn) { // locked = true; CrossPlatformInputManager.SetButtonDown ("RightStickClick"); Debug.Log ("Enter"); } } } void OnTriggerExit (Collider collider){ if (collider.gameObject.tag == "Enemy") { if (vLockOnTarget._inLockOn) { CrossPlatformInputManager.SetButtonDown ("RightStickClick"); Debug.Log ("Exit"); } } } void OnTriggerStay (Collider collider){ if (collider.gameObject.tag == "Enemy") { if (!vLockOnTarget._inLockOn) { CrossPlatformInputManager.SetButtonDown ("RightStickClick"); Debug.Log ("Stay"); } } } } when i said disable i didnt mean the component but just to say "no lockon needed". what is the behaviour u are getting now?
|
|
|
Post by sickscore on Aug 25, 2017 12:41:42 GMT
Please don't simulate a button press event or something like that, it's really bad practice. Unity has a built-in feature for your task -> Physics.OverlapSphere(), which will give you all enemies within a virtual sphere. The method also takes a layermask as parameter, which will limit your raycasts to a absolute minimum. Then you simply need to order all enemies by distance and you have your victim
|
|
|
Post by sickscore on Aug 25, 2017 12:42:59 GMT
This should work. www.dropbox.com/s/6clfid9o6g48etj/AutoLockOnClosestEnemy.cs?dl=0Just assign it to your player, define your enemy layers and play around with the radius. I included an option to see the radius within the editor. Cheers, sickscore EDIT: You should deactivate all default LockOn Inputs on your vLockOn component. Just click on the USE button next to the input.
|
|
|
Post by Jader on Aug 25, 2017 14:07:46 GMT
This should work. www.dropbox.com/s/6clfid9o6g48etj/AutoLockOnClosestEnemy.cs?dl=0Just assign it to your player, define your enemy layers and play around with the radius. I included an option to see the radius within the editor. Cheers, sickscore EDIT: You should deactivate all default LockOn Inputs on your vLockOn component. Just click on the USE button next to the input. hi sickscore, I'm got some errors, think it's because the version thtat i use. (Melee Template v2.0b)
|
|
|
Post by sickscore on Aug 25, 2017 14:39:03 GMT
Hmm..that's odd. Just check, how the classes are called. I'm pretty sure, vThirdPersonCamera has not changed throughout the different versions. Can't check myself, because I don't have older versions. Try to add "using Invector;". Maybe it's under a different namespace. Invector, can you confirm that?
|
|
|
Post by Jader on Aug 25, 2017 14:57:32 GMT
Hmm..that's odd. Just check, how the classes are called. I'm pretty sure, vThirdPersonCamera has not changed throughout the different versions. Can't check myself, because I don't have older versions. Try to add "using Invector;". Maybe it's under a different namespace. Invector , can you confirm that? I've made some modifications... vThirdPersonCamera > v3rdPersonCamera vLockOn > vLockOnTarget (maybe) But some erros still here. "...not contain a definition for..." vLock.onUnLockOnTarget vCamera.SetLockTarget vCamera.RemoveLockTarget I searched for functions with similar names but without success
|
|
|
Post by tharindu on Aug 25, 2017 16:20:27 GMT
Hmm..that's odd. Just check, how the classes are called. I'm pretty sure, vThirdPersonCamera has not changed throughout the different versions. Can't check myself, because I don't have older versions. Try to add "using Invector;". Maybe it's under a different namespace. Invector , can you confirm that? I think he's using mobile. Not sure if it's the same class for that. haven't tested mobile ever.
|
|
|
Post by Invector on Aug 25, 2017 18:03:40 GMT
Jader update to the last version, you will see several improvements and it will work ;)
|
|
|
Post by chrisoat on Aug 25, 2017 18:30:28 GMT
nice script sickscore! I have some use aswell for this, works perfect.
|
|
|
Post by Jader on Aug 25, 2017 21:44:32 GMT
Jader update to the last version, you will see several improvements and it will work ;) Thinking about... I'm afraid about how to import an update without broke my projects... What is correct method?
|
|