• Unity3D - Discussion
    5,004 replies, posted
[QUOTE=Venom Mk III;42440735]Unity is fine for this, a friend of mine made a dark, procedurally generated maze game in it. [editline]7th October 2013[/editline] As for quality its fine, just make sure you do things "the unity way" and you shouldn't have most of the performance problems people bitch about all the time.[/QUOTE] quality in unity is as high as you want it to go imo
[QUOTE=Johnny Guitar;42442722]quality in unity is as high as you want it to go imo[/QUOTE] For example, here's a really good looking game made in Unity: [URL]http://www.moddb.com/games/raindrop[/URL]
[QUOTE=Pelf;42442915]For example, here's a really good looking game made in Unity: [URL]http://www.moddb.com/games/raindrop[/URL][/QUOTE] I've been following that game, it looks stunning. But I mean, if you put effort into anything you will get good results.
So, I have a question -sort of. I'll try my best to explain what my problem is. My player script will have a weaponPrimary variable of the self defined type "Weapon". Each weapon will fire utilizing the same input -however- each weapon may behave differently. One weapon may require the player to press and hold the fire button, another weapon may be a one-off. Should I make the Weapon script an abstract class and then have my unique weapons extend from that? What do I do if I encounter a unique weapon that doesn't play nicely with my base class? Some of my weapons will need to communicate with the player that shot it, like a grappling hook (applying a force to the player). What should I do about that? Communication between objects has always given me a hard time just because there are so many different ways to do it.
[QUOTE=-Kiwibird-;42446984]So, I have a question -sort of. I'll try my best to explain what my problem is. My player script will have a weaponPrimary variable of the self defined type "Weapon". Each weapon will fire utilizing the same input -however- each weapon may behave differently. One weapon may require the player to press and hold the fire button, another weapon may be a one-off. Should I make the Weapon script an abstract class and then have my unique weapons extend from that? What do I do if I encounter a unique weapon that doesn't play nicely with my base class? Some of my weapons will need to communicate with the player that shot it, like a grappling hook (applying a force to the player). What should I do about that? Communication between objects has always given me a hard time just because there are so many different ways to do it.[/QUOTE] I would just use a weapon template. Just make a fire class, and you can customize it for any weapon. Example: WeaponTemplate ProjectileWeapon implements WeaponTemplate MachineGun extends ProjectileWeapon LaserWeapon implements WeaponTemplate LaserGun extends LaserWeapon ProjectileWeapon and LaserWeapon could have their own implementations of the Fire() function that is defined in WeaponTemplate.
Nice! I did my first scene and it's working (As far i can see), controls are simple, attack animation with first click and if you get bored press 2nd click! I can't realize how avoid those blobs when walking and avoid the no-collision with the walls... [unity]http://puu.sh/4KtJV.unity3d[/unity] Also i was testing image effects (don't judge me by use the "Free" pro version,i don't want to make money with it...Yet...) [img]http://puu.sh/4Ku3N.jpg[/img] [img]http://puu.sh/4Ku8o.jpg[/img]
[QUOTE=-Kiwibird-;42446984] Some of my weapons will need to communicate with the player that shot it, like a grappling hook (applying a force to the player). What should I do about that? Communication between objects has always given me a hard time just because there are so many different ways to do it.[/QUOTE] Terraria style grappling hook? If so, then the projectile for the grappling hook weapon requires a script like this (Requires a Collider with isTrigger checked): [code] using UnityEngine; using System.Collections; public class GrapplingHookPull : MonoBehaviour { public Transform owner; // The shooter private bool isAttached = false; // Others e.g.: public float hookRange = 10; // 10 Unity units private float currentHookRange; private bool retract = false; void FixedUpdate() { if(isAttached) { // Apply force to owner towards the hook direction // If you're using CharacterController for the player then you need to simulate physics yourself, as CC is // not affected by physics. } else { // Move the grappling hook projectile just like any other projectile until it reaches a certain range // After it reaches its max range and not collided with anything, then retract it for cosmetic effect // If using raycast to check for collision between hook and objects, do it here. // else see OnTriggerEnter . } } // Simple way to remove hook from the world when default jump button is pressed // If hook is cached and recycled then this won't work as it will delete the cached hook instead. Disable it instead. void Update() { if(Input.GetButtonDown("Jump")) { if(isAttached) Destroy(gameObject); } } // If the hook object is using a collider with isTrigger checked void OnTriggerEnter(Collider other) { if(!retract) { // Do a check whether the object collided is valid or not, if it is: isAttached = true; // else (e.g. enemy) ignore, or be creative, like pulling the object towards the owner. } } } [/code] If you're instantiating new hook object every time you're shooting a hook, then assign the shooter as the owner after instantiating the hook. Simplest way to do it: [code] GameObject clone; clone = Instantiate(prefab, transform.position, transform.rotation) as GameObject; clone.GetComponent<GrapplingHookPull>().owner = transform; [/code]
[QUOTE=Duskling;42448842]I would just use a weapon template. Just make a fire class, and you can customize it for any weapon. Example: WeaponTemplate ProjectileWeapon implements WeaponTemplate MachineGun extends ProjectileWeapon LaserWeapon implements WeaponTemplate LaserGun extends LaserWeapon ProjectileWeapon and LaserWeapon could have their own implementations of the Fire() function that is defined in WeaponTemplate.[/QUOTE] Haha! I never thought of making a template for a template. I feel so dumb now. That makes so much sense. Thank you! Before I had a WeaponTemplate with a Fire() and CeaseFire() function and then made my weapons directly from that. But it wasn't flexible enough for my needs. I'm going to try this out. [QUOTE=secundus;42450511]Terraria style grappling hook?[/QUOTE] Maybe? I am unfamiliar with Terraria's grappling hook. I have the functional code and such worked out, it's the efficient underlying structure that I'm having trouble with. For instance, you address it in the second part of your post. [QUOTE=secundus;42450511]If you're instantiating new hook object every time you're shooting a hook, then assign the shooter as the owner after instantiating the hook. Simplest way to do it: [code] GameObject clone; clone = Instantiate(prefab, transform.position, transform.rotation) as GameObject; clone.GetComponent<GrapplingHookPull>().owner = transform; [/code][/QUOTE] This was the original way I was doing it, but I soon found out it would require the owner script (the player script) to have all of the potential projectiles stored as prefabs and also know [I]which[/I] prefab to instantiate based on the player's current weapon. This would be fine if I only had one weapon. Utilizing Duskling's method, I can pass the owner as an argument through WeaponTemplate.Fire(Transform owner). And then decide what I want to do with the owner in the implemented classes. Correct me if I'm wrong about any of what I just said. I am in no way an expert on any of this. And I appreciate the feedback from both of you!
[QUOTE=-Kiwibird-;42451096] This was the original way I was doing it, but I soon found out it would require the [b]owner script (the player script) to have all of the potential projectiles stored as prefabs and also know [I]which[/I] prefab to instantiate based on the player's current weapon[/b]. This would be fine if I only had one weapon.[/QUOTE] Divide responsibility into different scripts, don't make everything into one. The player is not responsible for storing the projectile, its the weapon's responsibility to do so. The player is also not responsible to create the bullet and shoot, only telling the weapon to shoot. The weapon is not responsible on how the projectile reacts when it collides with something, its the projectiles responsibility to know about it. Other example would be health. Don't make the PlayerMovement script responsible for health and alive/dead states. Instead create a Health script to do it for you. Also, WeaponTemplate is the way to go. I did [url=http://facepunch.com/showthread.php?t=1260922&p=41034519&viewfull=1#post41034519]something similar back then[/url] but it was more of a combine everything into one rather than extending.
[QUOTE=secundus;42451710]Divide responsibility into different scripts, don't make everything into one. The player is not responsible for storing the projectile, its the weapon's responsibility to do so. The player is also not responsible to create the bullet and shoot, only telling the weapon to shoot. The weapon is not responsible on how the projectile reacts when it collides with something, its the projectiles responsibility to know about it. Other example would be health. Don't make the PlayerMovement script responsible for health and alive/dead states. Instead create a Health script to do it for you.[/QUOTE] Right. I've just recently been learning this and am now trying to account for features I may want in the future. Some situations are clearer to me than others, like the health system you mentioned. Situations that are less clear to me happen when there needs to be a lot of communication between scripts. For instance: What if some of the player's movement relied on information from a weapon's state? It becomes difficult for me, pretty much any time a conditional check on one script relies on another's. What would you say is the best approach?
[QUOTE=gonzalolog;42449632]Nice! I did my first scene and it's working (As far i can see), controls are simple, attack animation with first click and if you get bored press 2nd click! I can't realize how avoid those blobs when walking and avoid the no-collision with the walls... [unity]http://puu.sh/4KtJV.unity3d[/unity] Also i was testing image effects (don't judge me by use the "Free" pro version,i don't want to make money with it...Yet...) [img]http://puu.sh/4Ku3N.jpg[/img] [img]http://puu.sh/4Ku8o.jpg[/img][/QUOTE] less post processing more shaders that aren't the default ones
[QUOTE=-Kiwibird-;42452081]Right. I've just recently been learning this and am now trying to account for features I may want in the future. Some situations are clearer to me than others, like the health system you mentioned. Situations that are less clear to me happen when there needs to be a lot of communication between scripts. For instance: What if some of the player's movement relied on information from a weapon's state? It becomes difficult for me, pretty much any time a conditional check on one script relies on another's. What would you say is the best approach?[/QUOTE] AngryBots example uses a serializable SendMessage system (via SignalSender.js) to communicate between scripts (e.g. when health is deducted, tell particle emitter to emit blood effect and at the same time tell audiosource to play hit sound). Some example prefer to cache components on Awake() or Start() if its going to get accessed many times. If the weapon is used strictly by the player, you might as well cache the player movement component into the weapon script.
[QUOTE=Johnny Guitar;42442722]quality in unity is as high as you want it to go imo[/QUOTE] That's true for Unity Pro, but in Free version you're limited. And don't get me wrong - that's fine, and you still can make beautiful game in Unity Free.
[QUOTE=-Kiwibird-;42452081]Right. I've just recently been learning this and am now trying to account for features I may want in the future. Some situations are clearer to me than others, like the health system you mentioned. Situations that are less clear to me happen when there needs to be a lot of communication between scripts. For instance: What if some of the player's movement relied on information from a weapon's state? It becomes difficult for me, pretty much any time a conditional check on one script relies on another's. What would you say is the best approach?[/QUOTE] [URL="http://blog.sos.gd/controlled-glitch-effect/"]You don't always need a definite state.[/URL] The grappling hook constraints could just be applied after player movement, then you won't need additional code for swinging for example. The easiest way is probably snapping to less-or-equal rope length and rotating the movement vactor to be tangential. You can dampen movement depending on the angle relative to the hook, to avoid improbable trajectories. Similarly, if you set an on floor flag if you're snapped at a low angle, have additive jumps and hook into the jump trigger to break the rope, you can easily make a believable mechanic without adding dependencies. [editline]edit[/editline] Or don't break the rope automatically, that could be more fun depending on the rest of the gameplay.
I'm glad I could be of help, Kiwibird :)
[QUOTE=Tamschi;42455927][URL="http://blog.sos.gd/controlled-glitch-effect/"]You don't always need a definite state.[/URL] The grappling hook constraints could just be applied after player movement, then you won't need additional code for swinging for example. The easiest way is probably snapping to less-or-equal rope length and rotating the movement vactor to be tangential. You can dampen movement depending on the angle relative to the hook, to avoid improbable trajectories. Similarly, if you set an on floor flag if you're snapped at a low angle, have additive jumps and hook into the jump trigger to break the rope, you can easily make a believable mechanic without adding dependencies. [editline]edit[/editline] Or don't break the rope automatically, that could be more fun depending on the rest of the gameplay.[/QUOTE] I'm not having trouble with any of the functional code, I'm actually quite decent at that, in my opinion. What I'm having trouble with, is making my code flexible and efficient. As in, modular programming. The reason I get hung up on communications between objects is because I want my code to be flexible(within reason). Let's say, for example, there is a movement script on the player, and a health system on the player. Health.cs MovementPlayer.cs The lower the player's health, the slower they move. Simple enough. There are several different ways you could approach this, some sloppier than others. You could have the MovementPlayer script constantly read the player's health and have that modify the player's final move speed. This is good in that your move script does all the work and your health script is completely oblivious. This is bad in that you're constantly reading the player's health(inefficient). This also makes the movement script require a Health script to read data from(inflexible). You could have the Health script broadcast the message: "UpdateHealth", currentHealth when the player's health changes. Then have that function and a local health variable on the MovementPlayer script. This is good in that you only update the health when the health ACTUALLY changes(efficient). This is bad in that if you wanted to change that function name, you would have to do it in two locations, possibly more as the project advances(inflexible). Broadcast message is also slow and can only send one argument(inefficient and inflexible). I'm not saying I would actually use one of these methods, I am just showing how an end goal can be accomplished in different ways. There are pros and cons to each method. Also, when I get home, I'm going to take a look at the AngryBots demo. I assume what I'm talking about just takes time to learn, and can't be easily taught. I certainly am further along with this than I was a year ago. I didn't even know what interfaces and abstract classes [I]were[/I] a year ago. Well, that was long winded.
I need the assistance of a math ninja here. Using a simple sine wave, I am creating a basic camera oscillation effect. My sine wave is as follows: [CODE] Mathf.Sin(Time.time * oscillationSpeed) * oscillationMagnitude; [/CODE] This works fine, but I am in a bit of a jam. I want a nice way to... slide back across the wave and back to 0 sort of. The camera only oscillates when the character controller is moving, so I want the oscillation offset to return to 0 when the character is not moving. I suppose I could just Lerp back to the default position, but I would rather not do that.
I have a silly question of multiple cases, all of them maybe really hard to ask...So here we go... 1) If i buy the licence per month, i can publish a game, that's clearly... 2) If i do the game on a free version, but when i finish it, i pay 70 dollars for make it pro then i can publish it, it's valid? 3) If i use a pirate pro version, finish it, and i decide to go into unity pro, on subscription of course, it's valid? 4) And how anyone can see that i'm using a legit copy of unity when i publish a game I'm not attempting to do anything of that, because i don't have a team, i can't create music, i'm very lazy and i don't have the correct dev machine for create games (In the way that i luckily can run my island example at 20fps and the ants example at 50)
[QUOTE=-Kiwibird-;42459301]I'm not having trouble with any of the functional code, I'm actually quite decent at that, in my opinion. What I'm having trouble with, is making my code flexible and efficient. As in, modular programming. The reason I get hung up on communications between objects is because I want my code to be flexible(within reason). Let's say, for example, there is a movement script on the player, and a health system on the player. Health.cs MovementPlayer.cs The lower the player's health, the slower they move. Simple enough. There are several different ways you could approach this, some sloppier than others. You could have the MovementPlayer script constantly read the player's health and have that modify the player's final move speed. This is good in that your move script does all the work and your health script is completely oblivious. This is bad in that you're constantly reading the player's health(inefficient). This also makes the movement script require a Health script to read data from(inflexible). You could have the Health script broadcast the message: "UpdateHealth", currentHealth when the player's health changes. Then have that function and a local health variable on the MovementPlayer script. This is good in that you only update the health when the health ACTUALLY changes(efficient). This is bad in that if you wanted to change that function name, you would have to do it in two locations, possibly more as the project advances(inflexible). Broadcast message is also slow and can only send one argument(inefficient and inflexible). I'm not saying I would actually use one of these methods, I am just showing how an end goal can be accomplished in different ways. There are pros and cons to each method. Also, when I get home, I'm going to take a look at the AngryBots demo. I assume what I'm talking about just takes time to learn, and can't be easily taught. I certainly am further along with this than I was a year ago. I didn't even know what interfaces and abstract classes [I]were[/I] a year ago. Well, that was long winded.[/QUOTE] Have you tried something like this? Health.cs [code] using UnityEngine; using System; using System.Collections; public class Health : MonoBehaviour { int health = 100; public Action<int> OnHealthChanged = null; public void ModifyHealth(int amt){ health += amt; OnHealthChanged( health ); } } [/code] Player.cs [code] using UnityEngine; using System.Collections; public class Player : MonoBehaviour { Health health = null; void Start(){ health = gameObject.AddComponent<Health>(); health.OnHealthChanged += HandlePlayerHealthChanged; health.ModifyHealth(0); health.ModifyHealth(-20); } void OnDestroy(){ health.OnHealthChanged -= HandlePlayerHealthChanged; } void HandlePlayerHealthChanged(int newHealth){ Debug.Log( "Player health changed: " + newHealth ); } } [/code]
[QUOTE=Duskling;42459692]I need the assistance of a math ninja here. Using a simple sine wave, I am creating a basic camera oscillation effect. My sine wave is as follows: [CODE] Mathf.Sin(Time.time * oscillationSpeed) * oscillationMagnitude; [/CODE] This works fine, but I am in a bit of a jam. I want a nice way to... slide back across the wave and back to 0 sort of. The camera only oscillates when the character controller is moving, so I want the oscillation offset to return to 0 when the character is not moving. I suppose I could just Lerp back to the default position, but I would rather not do that.[/QUOTE] Keep it going until Time.time * oscillationSpeed reaches the next multiple of Pi.
[QUOTE=Chris220;42460178]Keep it going until Time.time * oscillationSpeed reaches the next multiple of Pi.[/QUOTE] How would I check for this? Can you give me an example?
Just testing some mecanim stuff. Move: [B]WASD[/B]&#8203; Run: [B]Left Shift[/B] Jump: [B]Space[/B] Cam Zoom: [B]Mouse Wheel[/B] [unity]https://dl.dropboxusercontent.com/u/51366441/Project/UnityTest.unity3d[/unity]
[QUOTE=Duskling;42460655]How would I check for this? Can you give me an example?[/QUOTE] Try using the modulus operator: [code] if ( Mathf.Approximately((Time.time * oscillationSpeed) % Mathf.PI, 0.0f) == true ) { //Do stuff } [/code]
[QUOTE=gonzalolog;42459878]I have a silly question of multiple cases, all of them maybe really hard to ask...So here we go... 1) If i buy the licence per month, i can publish a game, that's clearly... 2) If i do the game on a free version, but when i finish it, i pay 70 dollars for make it pro then i can publish it, it's valid? 3) If i use a pirate pro version, finish it, and i decide to go into unity pro, on subscription of course, it's valid? 4) And how anyone can see that i'm using a legit copy of unity when i publish a game I'm not attempting to do anything of that, because i don't have a team, i can't create music, i'm very lazy and i don't have the correct dev machine for create games (In the way that i luckily can run my island example at 20fps and the ants example at 50)[/QUOTE] 1.) Yes 2.) Yes 3.) that's warez, don't discuss that here. 4.) that's warez, don't discuss that here.
It's fine to discuss it as long as you aren't contributing to anything illegal.. For number 3, no it isn't legal. Best not to do it. Just use Free to do the majority of development and buy Pro to polish and publish if you feel it is worth it. I'm not going to comment on number 4(That one IS a grey area), just don't pirate it.
I didn't really test what I posted earlier, but it should have worked in theory. I tested the following code which [I]did[/I] work -but- depending on the oscillation speed and the frame rate, this may fail to execute sometimes. You could try scaling the comparison with Time.deltaTime and such. [code] if ( (Time.time * oscillationSpeed) % Mathf.PI <= 0.2f ) { //Do stuff } [/code]
[QUOTE=-Kiwibird-;42459301]I'm not having trouble with any of the functional code, I'm actually quite decent at that, in my opinion. What I'm having trouble with, is making my code flexible and efficient. As in, modular programming. The reason I get hung up on communications between objects is because I want my code to be flexible(within reason). Let's say, for example, there is a movement script on the player, and a health system on the player. Health.cs MovementPlayer.cs The lower the player's health, the slower they move. Simple enough. There are several different ways you could approach this, some sloppier than others. You could have the MovementPlayer script constantly read the player's health and have that modify the player's final move speed. This is good in that your move script does all the work and your health script is completely oblivious. This is bad in that you're constantly reading the player's health(inefficient). This also makes the movement script require a Health script to read data from(inflexible). You could have the Health script broadcast the message: "UpdateHealth", currentHealth when the player's health changes. Then have that function and a local health variable on the MovementPlayer script. This is good in that you only update the health when the health ACTUALLY changes(efficient). This is bad in that if you wanted to change that function name, you would have to do it in two locations, possibly more as the project advances(inflexible). Broadcast message is also slow and can only send one argument(inefficient and inflexible). I'm not saying I would actually use one of these methods, I am just showing how an end goal can be accomplished in different ways. There are pros and cons to each method. Also, when I get home, I'm going to take a look at the AngryBots demo. I assume what I'm talking about just takes time to learn, and can't be easily taught. I certainly am further along with this than I was a year ago. I didn't even know what interfaces and abstract classes [I]were[/I] a year ago. Well, that was long winded.[/QUOTE] What about having a static class with some variables in it like this: Player.cs [code]using UnityEngine; using System.Collections; public class Player : MonoBehaviour { float health; void Update { health = PlayerData.Health; // Do other stuff } }[/code] Health.cs [code]using UnityEngine; using System.Collections; public class Health : MonoBehaviour { float health; void Update { health = whatever; PlayerData.Health = health; } }[/code] PlayerData.cs [code]using UnityEngine; using System.Collections; public static class PlayerData : MonoBehaviour { public static float Health; }[/code]
[QUOTE=Pelf;42464752]What about having a static class with some variables in it like this: code[/QUOTE] Seeing the disagrees, could someone explain why this isn't a good approach? I'm still fairly new to programming.
[QUOTE=Pelf;42468634]Seeing the disagrees, could someone explain why this isn't a good approach? I'm still fairly new to programming.[/QUOTE] I would say you received the disagrees for the following reasons: -You modify the static variable "Health" externally, in the script 'Health.cs'. This unnecessarily obfuscates the code. Generally, the variable re-assignment should happen within the same script. If you need external scripts to modify the variable, then make a public function that the local and external scripts can utilize, like "UpdateHealth(float newHealth)". This keeps the modification of data to one line of code and makes it easier to decipher. -You create local variables for health in both the 'Player.cs' script and the 'Health.cs' script. This is unnecessary as you already have the static variable 'Health' to read from(and reading is all you should need). So, it'd look like the following: Player.cs [code] using UnityEngine; using System.Collections; public class Player : MonoBehaviour { void Update { transform.Translate(finalVelocity * PlayerData.Health * Time.deltaTime); } } [/code] Health.cs [code] using UnityEngine; using System.Collections; public class Health : MonoBehaviour { public void ApplyDamage(float damage) { float newHealth = PlayerData.health - damage; PlayerData.UpdateHealth(newHealth); } } [/code] PlayerData.cs [code] using UnityEngine; using System.Collections; public static class PlayerData : MonoBehaviour { public static float Health; public void UpdateHealth(float newHealth) { PlayerData.Health = newHealth; } } [/code] Even with these edits, it is still rather obfuscated because of the redundant PlayerData class. You could just do everything you needed with Player.cs and Health.cs. Because the Health.cs script relies on the PlayerData.cs script to keep track of the health, you lose flexibility. Right now, the Health.cs script can only be used for Player entities. If you kept track of the health as a closed system, you could use the Health.cs script on entities that aren't a Player. Please feel free to correct or add to any of the information above.
[QUOTE=LuaChobo;42470541]this fucking bLOCK BUG is killing me I think its just ufps getting stuck in the block for like a frame, causing unities physics engine to just spit it out from underneath the player[/QUOTE] Try looking at these: [url]http://answers.unity3d.com/questions/8207/charactercontroller-falls-through-or-slips-off-mov.html[/url] [url]http://answers.unity3d.com/questions/17832/make-a-platform-push-a-character-controller.html[/url]
Sorry, you need to Log In to post a reply to this thread.