• Unity3D - Discussion
    5,004 replies, posted
[unity]https://dl.dropboxusercontent.com/u/10492850/unity/unity.unity3d[/unity] Downloaded unity and made that in a couple hours today (R toggles reverse). Unity is great fun, but I have no idea how to make the car less flip-happy. I read on some stuff that suggested making 'anti-roll bars', and they help, but at a certain speed it just flips out. It just a rigidbody and four wheelcollider in case that's important. Maybe I'll just make the wheels have less grip and steer less the faster it goes...
[QUOTE=galimatias;44732216]Downloaded unity and made that in a couple hours today (R toggles reverse). Unity is great fun, but I have no idea how to make the car less flip-happy. I read on some stuff that suggested making 'anti-roll bars', and they help, but at a certain speed it just flips out. It just a rigidbody and four wheelcollider in case that's important. Maybe I'll just make the wheels have less grip and steer less the faster it goes...[/QUOTE] That's pretty cool for just a couple hours with Unity. You could add some sort of weak keep-upright force, sort-of like what was in Garry's Mod. Basically calculate a vector that would move the car to it's upright position based on it's rotation, and apply that force externally to the car. It sounds complicated, but I don't think it would be terribly difficult.
[QUOTE=galimatias;44732216]Downloaded unity and made that in a couple hours today (R toggles reverse). Unity is great fun, but I have no idea how to make the car less flip-happy. I read on some stuff that suggested making 'anti-roll bars', and they help, but at a certain speed it just flips out. It just a rigidbody and four wheelcollider in case that's important. Maybe I'll just make the wheels have less grip and steer less the faster it goes...[/QUOTE] Try setting the centre of mass of the rigidbody lower. That should make it a bit more stable. [url=https://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-centerOfMass.html]rigidbody.centerOfMass[/url]
What's the smartest way of creating multiple levels in a 2D game, like a platformer or something like that. Multiple scenes or what?
[QUOTE=Persious;44746401]What's the smartest way of creating multiple levels in a 2D game, like a platformer or something like that. Multiple scenes or what?[/QUOTE] Yes, usually multiple scenes. But its also possible to make one loader scene that instantiates the level based on information from a file. For example: You have a text file that contains which objects are at what position, then spawn the level from that using a base-scene. But that approach is rarely usable.
I need some help with a countdown timer. Basically I want a countdown timer of 5 seconds to start going down only WHILE a button is pressed. Once the button is unpressed I want the timer to stop, and to slowly add time onto it. If the timer is depleted, nothing will happen when the button is pressed. I'm having trouble figuring it out because the way I am doing it now is like this: [code] void Start () { endTime = Time.time + startTime; void Update () { float timeLeft = endTime - Time.time; if(timeLeft < 0) timeLeft = 0; }[/code] Since it uses Time.time I'm not sure how best to do it. Any ideas?
[QUOTE=Over-Run;44747266]I need some help with a countdown timer. Basically I want a countdown timer of 5 seconds to start going down only WHILE a button is pressed. Once the button is unpressed I want the timer to stop, and to slowly add time onto it. If the timer is depleted, nothing will happen when the button is pressed. I'm having trouble figuring it out because the way I am doing it now is like this: [code] void Start () { endTime = Time.time + startTime; void Update () { float timeLeft = endTime - Time.time; if(timeLeft < 0) timeLeft = 0; }[/code] Since it uses Time.time I'm not sure how best to do it. Any ideas?[/QUOTE] Typing on my tablet so here we go [code] float timer; float targetTime = 5f; void Update() { timer += Time.deltaTime; if( timer >= targetTime ) { DoThing(); timer = 0f; } } [/code] This is a simple timer that invokes DoThing every 5 seconds. I'm sure you could adapt it to your use.
I added some blender shortcuts to Unity. [url]https://github.com/rvzy/BlenderShortcutsUnity[/url]
[QUOTE=Asgard;44747393]Typing on my tablet so here we go [code] float timer; float targetTime = 5f; void Update() { timer += Time.deltaTime; if( timer >= targetTime ) { DoThing(); timer = 0f; } } [/code] This is a simple timer that invokes DoThing every 5 seconds. I'm sure you could adapt it to your use.[/QUOTE] That worked great to stop my spell after 5 seconds. How would I go about making it once the spell runs out of time, it waits like a 2 seconds, and then starts to charge it up, so you have another 5 second cool down?
[QUOTE=Felheart;44746990]Yes, usually multiple scenes. But its also possible to make one loader scene that instantiates the level based on information from a file. For example: You have a text file that contains which objects are at what position, then spawn the level from that using a base-scene. But that approach is rarely usable.[/QUOTE] I'm using both for my game. I use separate scenes for standard levels, and for custom levels I read from a text file. I would recommend sticking with multiple scenes though because writing a level loader can be a pain in the ass and use up a lot of your time. [editline]edit[/editline] I should made a video of my level editor
You could use a coroutine and a flag, where the timer only runs if the flag is true. So what you could do is in the coroutine: Flag = false; yield return new WaitForSeconds(2); Flag = true;
[QUOTE=Asgard;44747668]You could use a coroutine and a flag, where the timer only runs if the flag is true. So what you could do is in the coroutine: Flag = false; yield return new WaitForSeconds(2); Flag = true;[/QUOTE] I see, would I call that CoRoutine in the if statement for setting the targetTime = 0?
The obvious best solution. [code] using System; using UnityEngine; using System.Collections.Generic; class Magic : Monobehaviour { private delegate void GenericDelegate(); private event GenericDelegate Tick; void Start() { GO(); } void GO() { int count = 0; GenericDelegate cooldowndel = () => { if(count >= 5) { GO(); } else count++; }; GenericDelegate preCooldownDel = null; preCooldownDel = () => { if (count >= 2) { count = 0; Tick += cooldowndel; Tick -= preCooldownDel; } else count++; }; GenericDelegate castDel = null; castDel = () => { if (count >= 5) { count = 0; Tick += preCooldownDel; Tick -= castDel; } else { CastSpell(); count++; } }; Tick -= cooldowndel; Tick += castDel; } void Update() { if (Tick != null) Tick(); } void CastSpell() { //MAGIC } } [/code]
When you say button, do you mean keyboard buttons or GUI button? From what you described, it sounds like a magic channeling mechanic, like healing magic in Skyrim. If that's what you meant, then it should be something like: [code] private float mana; public float maxMana = 5; public float regenPerSecond = 1; public float delayBeforeRegen = 2; public float depletionPerSecond = 1; private float lastFireTime = -1; void Start() { mana = maxMana; } void OnGUI() { GUILayout.Label("Mana: "+mana); } void Update() { if(Input.GetButton("Fire1")) { // Set current time as last firing time lastFireTime = Time.time; // Do stuff (like magic channelling) when mana is available if(mana > 0) { //DoStuff(); mana -= Time.deltaTime * depletionPerSecond; } else { //DoFumbleStuff(); } } else { // After exceed delay, then regen if(Time.time > lastFireTime + delayBeforeRegen) mana = (mana < maxMana) ? (mana+Time.deltaTime * regenPerSecond) : maxMana; } }[/code]
[QUOTE=secundus;44747842]When you say button, do you mean keyboard buttons or GUI button? From what you described, it sounds like a magic channeling mechanic, like healing magic in Skyrim. If that's what you meant, then it should be something like: [code] private float mana; public float maxMana = 5; public float regenPerSecond = 1; public float delayBeforeRegen = 2; public float depletionPerSecond = 1; private float lastFireTime = -1; void Start() { mana = maxMana; } void OnGUI() { GUILayout.Label("Mana: "+mana); } void Update() { if(Input.GetButton("Fire1")) { // Set current time as last firing time lastFireTime = Time.time; // Do stuff (like magic channelling) when mana is available if(mana > 0) { //DoStuff(); mana -= Time.deltaTime * depletionPerSecond; } else { //DoFumbleStuff(); } } else { // After exceed delay, then regen if(Time.time > lastFireTime + delayBeforeRegen) mana = (mana < maxMana) ? (mana+Time.deltaTime * regenPerSecond) : maxMana; } }[/code][/QUOTE] I mean a button on a Razer Hydra controller. Basically I hold the trigger, light turns on, I want the timer to start when the trigger is pressed. If trigger is unpressed/runs out of power, then it starts slowly adding time back onto it. Eventually I also want to add magic orbs that give more time when you run into them. I will look into your solution thank you
[QUOTE=Pelf;44747650]I'm using both for my game. I use separate scenes for standard levels, and for custom levels I read from a text file. I would recommend sticking with multiple scenes though because writing a level loader can be a pain in the ass and use up a lot of your time.[/QUOTE] Multiple scenes are easier to do, but level loader would be better if you want to use an external level editor (e.g. Tiled). That's the only way to add modding support to Unity game, am I right? Since you can't use Unity editor to make a level and somehow add it to existing, compiled game.
[QUOTE=Deseteral;44748272]Multiple scenes are easier to do, but level loader would be better if you want to use an external level editor (e.g. Tiled). That's the only way to add modding support to Unity game, am I right? Since you can't use Unity editor to make a level and somehow add it to existing, compiled game.[/QUOTE] As far as I know yeah. Even an ingame editor (like what I'm doing) requires some level loader system to instantiate prefabs from a file.
Turns out that my car was so flippy because I used values that were a couple hundred times too low, or confused 1 with 0. Oops, I guess. I've fixed that and also added some wheels and a better track. [unity]https://dl.dropboxusercontent.com/u/10492850/unity/unity.unity3d[/unity] How do you guys like those driving physics? WIP obviously.
For you being a beginner at Unity *I believe that's what you said* Then you're doing great.
Why do so many Unity games have this really awful shadow mapping?
[QUOTE=Tamschi;44750014]Why do so many Unity games have this really awful shadow mapping?[/QUOTE] Unity free provides a single way to do shadows and it only looks okay at best, so I presume it's because most people use that.
So going from what I previously said about having a timer. I got it to work using the above suggestions so thanks a lot. I now have a new question regarding adding to that timer. I have a gameobject called LightPowerup. When the player walks into it, I want it to add time onto the light power. So if you walk over 2, you got an extra 10 seconds of light time. I thought it would be quite easy to detect the collisions but I think I'm doing it wrong. In my MovementControllerScript I have this method: [code] void OnControllerColliderHit(Collision collision){ LightPowerup lightPowerupScript = collision.collider.gameObject.GetComponent<LightPowerup>(); if(lightPowerupScript != null){ Debug.Log("Hit Character"); Destroy(this.gameObject); }[/code] However, it doesn't detect itself hitting off the light powerup. The Controller and the powerup have colliders attached so not sure what I'm doing wrong. When I do manage to get colliding working, how should I go about adding to the time in another script? EDIT Got it working
I finally got networking done on my game after allot of testing, but one issue, how do I make it so a client can join the server which is on a different level and the client automatically changes to that level? Currently, clients can join the server, then the server can change level and it's all fine for the clients in the level, they accept the change and load the level, but others that attempt to join the server, it doesn't go to well. Networking in Unity is really stressful right now for me. The error I get when they join after level change "Received state update for view ID SceneID: 1 Level Prefix: 0 but no initial state has ever been sent. Ignoring message."
[QUOTE=AnonTakesOver;44752130]I finally got networking done on my game after allot of testing, but one issue, how do I make it so a client can join the server which is on a different level and the client automatically changes to that level? Currently, clients can join the server, then the server can change level and it's all fine for the clients in the level, they accept the change and load the level, but others that attempt to join the server, it doesn't go to well. Networking in Unity is really stressful right now for me. The error I get when they join after level change "Received state update for view ID SceneID: 1 Level Prefix: 0 but no initial state has ever been sent. Ignoring message."[/QUOTE] Your server should send an RPC to clients when they connect telling them to load the new level.
[QUOTE=KillaMaaki;44752174]Your server should send an RPC to clients when they connect telling them to load the new level.[/QUOTE] Oh my god, that was one line of code.... so easy. Sorry, when I get stressed, I tend to not think straight. Thank you!
When a client connects to the server, the server should tell the client what map the client should load. RPC Buffer can be used for this purpose. [url=https://docs.unity3d.com/Documentation/Components/net-RPCDetails.html]Unity manual about RPC Buffer[/url]
[QUOTE=BackwardSpy;44671256]How do I stop an animation from teleporting my object back to the position it was in when I made the animation? I've tried removing all the keys pertaining to his position in the animation, I've tried turning 'apply root motion' on and off, nothing seems to work.[/QUOTE] Anyone got any ideas for this? As I mentioned in the post after this, I have already tried putting it in an empty game object, no luck.
So when I shoot a fireball at a wall, I want it to fizz out and get smaller or something before destroying the object. How should I do this? Right now I shoot the fireball and when it hits something it plays a sound but gets destroyed straight away so it just disappears. It's just a particle system.
Make another particle that does what you want (fireball getting smaller). Make it as a prefab, and on your fireball script, reference the created prefab and spawn it when the fireball hits something.
A shot in the dark Why is it when I force RenderTextureFormat.ARGB32 on every device, which makes every color channel have 8 bit precision. Make my shader act normal on my nexus and different on a mobile device? I set it to low precision on purpose.
Sorry, you need to Log In to post a reply to this thread.