• Unity3D - Discussion
    5,004 replies, posted
[QUOTE=CrashLemon;42461293]Just testing some mecanim stuff. Move: [B]WASD[/B]​ 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] Camera orientation based on user input? Like... Mathf.Rad2Deg * Mathf.ATan2(180* Input.GetAxis("Horizontal"), 90* Input.GetAxis("Vertical")) + this.gameObject.transform.rotation.y; ?
[QUOTE=Skibur;42471836]Camera orientation based on user input? Like... Mathf.Rad2Deg * Mathf.ATan2(180* Input.GetAxis("Horizontal"), 90* Input.GetAxis("Vertical")) + this.gameObject.transform.rotation.y; ?[/QUOTE] Still learning but it looks something like this at the moment: [code]Vector3 pos = transform.position + attachOffset; Vector3 targetPos = transform.position + cameraOffset; Vector3 tempPos = Vector3.zero; float mY = Input.GetAxis ("Mouse Y"); float mX = Input.GetAxis ("Mouse X"); float mW = Input.GetAxis ("Mouse ScrollWheel"); if (mW != 0) distance = Mathf.Clamp ( (distance - mW * 3), _minDistance, _maxDistance ); _targetAngle.eulerAngles += new Vector3( -mY * 1.2f, mX * 2.3f, 0 ); _realAngle = Quaternion.Lerp ( _realAngle, _targetAngle, lerpSpeed * Time.deltaTime ); Camera.main.transform.rotation = _realAngle; Quaternion tempAngle = Quaternion.identity; tempAngle.eulerAngles = _realAngle.eulerAngles + cameraOffset; Vector3 forward = tempAngle * Vector3.forward; RaycastHit hit; if (Physics.Raycast( pos, forward * -1, out hit, distance )) { _realDistance = hit.distance; } else _realDistance = distance; Camera.main.transform.position = pos + ( tempAngle * Vector3.forward * -_realDistance );[/code]
[QUOTE=CrashLemon;42472310]Still learning but it looks something like this at the moment: [code]Vector3 pos = transform.position + attachOffset; Vector3 targetPos = transform.position + cameraOffset; Vector3 tempPos = Vector3.zero; float mY = Input.GetAxis ("Mouse Y"); float mX = Input.GetAxis ("Mouse X"); float mW = Input.GetAxis ("Mouse ScrollWheel"); if (mW != 0) distance = Mathf.Clamp ( (distance - mW * 3), _minDistance, _maxDistance ); _targetAngle.eulerAngles += new Vector3( -mY * 1.2f, mX * 2.3f, 0 ); _realAngle = Quaternion.Lerp ( _realAngle, _targetAngle, lerpSpeed * Time.deltaTime ); Camera.main.transform.rotation = _realAngle; Quaternion tempAngle = Quaternion.identity; tempAngle.eulerAngles = _realAngle.eulerAngles + cameraOffset; Vector3 forward = tempAngle * Vector3.forward; RaycastHit hit; if (Physics.Raycast( pos, forward * -1, out hit, distance )) { _realDistance = hit.distance; } else _realDistance = distance; Camera.main.transform.position = pos + ( tempAngle * Vector3.forward * -_realDistance );[/code][/QUOTE] I see, Nice. My script is a bit more directive on the variable it gets, but it get messy a bit.
[QUOTE=CrashLemon;42461293]Just testing some mecanim stuff. Move: [B]WASD[/B]​ 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] I probably have spent 2 hours+ jumping around in this today because I have left it on my third monitor. Woop. I am so good at not reading my C++ Early Objects book. Thank you.
[QUOTE=-Kiwibird-;42470111]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(PlayerData.Health - damage); } } [/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. 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] Change [CODE]float newHealth = PlayerData.health - damage; PlayerData.UpdateHealth(PlayerData.Health - damage);[/CODE] to [CODE]float newHealth = PlayerData.health - damage; PlayerData.UpdateHealth(newHealth);[/CODE] or [CODE]PlayerData.UpdateHealth(PlayerData.Health - damage);[/CODE] Either use the newHealth variable that you instantiated in the ApplyDamage method, or simply don't use them at all.
[QUOTE=Skibur;42473800]Change [CODE]float newHealth = PlayerData.health - damage; PlayerData.UpdateHealth(PlayerData.Health - damage);[/CODE] to [CODE]float newHealth = PlayerData.health - damage; PlayerData.UpdateHealth(newHealth);[/CODE] or [CODE]PlayerData.UpdateHealth(PlayerData.Health - damage);[/CODE] Either use the newHealth variable that you instantiated in the ApplyDamage method, or simply don't use them at all.[/QUOTE] Yeah, thanks for the catch. I added the "newHealth" variable after the fact but forgot to replace the 'PlayerData.Health - damage' line with it. Performing operations where the function arguments go bothers me for some reason. It just feels... dirty.
So I just started looking into torque 3d and it seems like its a way better deal than unity in every single way?
[QUOTE=LuaChobo;42476745]torque 3d is a horrible engine for anything thats more complex than "run to end of level"[/QUOTE] explain/elaborate
[B]The color of my GO doesn't function on my phone; however, it works perfectly fine in-editor.[/B] [IMG]http://i.imgur.com/wfVunC6.png[/IMG] The color of the gameobject is controlled by the following script. [CODE]using UnityEngine; using System.Collections; public class RangeScript : MonoBehaviour { //Public variables //Private variables //Visible private variables void Update() { //Changes visual radius of visualizer TurretScript turretScript = transform.parent.GetComponent<TurretScript>(); transform.localScale = new Vector3(turretScript.Range, 0, turretScript.Range) / 10; //FIX: Find a better way to check turrets element. This looks stupid. //Changes color depending on turrets element if (turretScript.Element == TurretScript.ElementType.Earth) { renderer.material.color = new Color(0.4f, 0.2f, 0); } if (turretScript.Element == TurretScript.ElementType.Fire) { renderer.material.color = Color.red; } if (turretScript.Element == TurretScript.ElementType.Water) { renderer.material.color = Color.blue; } } }[/CODE] Essentially, it'll check a different GO and change color depending on an Enum variable. If you refer to the screenshot you'll notice it works fine in-editor, but when I build it to my phone it'll change the color to black instead of what I'd like it to change to (Brown, Red or Blue). I'm using a transparent/diffuse shader on the material, and it doesn't have anything to do with screen settings, as it looks fine when running in-editor through Unity Remote on my phone. Any clue what's going on?
[QUOTE=LuaChobo;42476885]slow clunky ugly go for it and try it out if you want but you will die inside[/QUOTE] when did you use it last? cause apparently its gotten a lot better since they went open source in februrary.
Got landing on moving planets to work. Before now, you would slide along the surface until you reached the trailing end and then rock back and forth. [video=youtube;aCanoi9yKn8]http://www.youtube.com/watch?v=aCanoi9yKn8[/video] [editline]10th October 2013[/editline] I'm so pumped! This really opens up possibilities for gameplay.
[QUOTE=LuaChobo;42477210]late last year i can say without doubt that if you arent hacking at the internals to make it better, its not going to be anywhere [b]near as good as unity.[/b] and if you still want to hack at the internals then you are better off using something that isnt so complex and retarded.[/QUOTE] I do plan to hack at the internals a bit if its necessary, but secondly, it supports Oculus rift without without me paying 1,500$ for it, and that's a pretty nice gain in my opinion.
[QUOTE=Doom;42476869][B]The color of my GO doesn't function on my phone; however, it works perfectly fine in-editor.[/B] [IMG]http://i.imgur.com/wfVunC6.png[/IMG] The color of the gameobject is controlled by the following script. [CODE]using UnityEngine; using System.Collections; public class RangeScript : MonoBehaviour { //Public variables //Private variables //Visible private variables void Update() { //Changes visual radius of visualizer TurretScript turretScript = transform.parent.GetComponent<TurretScript>(); transform.localScale = new Vector3(turretScript.Range, 0, turretScript.Range) / 10; //FIX: Find a better way to check turrets element. This looks stupid. //Changes color depending on turrets element if (turretScript.Element == TurretScript.ElementType.Earth) { renderer.material.color = new Color(0.4f, 0.2f, 0); } if (turretScript.Element == TurretScript.ElementType.Fire) { renderer.material.color = Color.red; } if (turretScript.Element == TurretScript.ElementType.Water) { renderer.material.color = Color.blue; } } }[/CODE] Essentially, it'll check a different GO and change color depending on an Enum variable. If you refer to the screenshot you'll notice it works fine in-editor, but when I build it to my phone it'll change the color to black instead of what I'd like it to change to (Brown, Red or Blue). I'm using a transparent/diffuse shader on the material, and it doesn't have anything to do with screen settings, as it looks fine when running in-editor through Unity Remote on my phone. Any clue what's going on?[/QUOTE] Most probably the implementation of transparent/diffuse shader that was used is not compatible with your mobile renderer. Each shader can have several implementations, if the first implementation is not compatible, then it goes down to other implementations (see [url=http://docs.unity3d.com/Documentation/Manual/Shaders.html]here for Unity shader info[/url]. Quick google shows that most popular question regarding transparent/diffuse shader is that whether its applicable/expensive for mobile. Search for implementations of Mobile Transparent Vertex Color shader, I think thats what you need.
[QUOTE]Search for implementations of Mobile Transparent Vertex Color shader, I think thats what you need.[/QUOTE] Thank you so much, that worked really well! Actually also made the colors look a lot more vibrant than the original shader did. :)
[QUOTE=LuaChobo;42477841]its apples and oranges but the apple costs more money so up to you[/QUOTE] dont be hatin on torque, marble blast gold is one of my favourite games.
[QUOTE=Pelf;42477483]Got landing on moving planets to work. Before now, you would slide along the surface until you reached the trailing end and then rock back and forth. [video=youtube;aCanoi9yKn8]http://www.youtube.com/watch?v=aCanoi9yKn8[/video] [editline]10th October 2013[/editline] I'm so pumped! This really opens up possibilities for gameplay.[/QUOTE] And, of course, it's riddled with bugs and hardly works.
[QUOTE=Pelf;42489231]And, of course, it's riddled with bugs and hardly works.[/QUOTE] What about running the physics in a rotating coordinate system if you're close to a planet? That should make it more stable due to lack of velocity and if you fade in a small amount of drag near the surface you get relative-speed air braking for free. [URL="http://en.wikipedia.org/wiki/Rotating_reference_frame#Relating_rotating_frames_to_stationary_frames"]The transformations are relatively straightforward[/URL]. You can probably just step into the rotating system with t=0 each frame and step out at an angle dependent on the frame time and planet rotation.
I need animations for a prototype, so I decided to give it a go in Blender. Rigging is really fun once you get the hang of it. [IMG]http://puu.sh/4O43O.jpg[/IMG] The model isn't mine. [unity]https://dl.dropboxusercontent.com/u/41313766/Dont delete/Model/model.unity3d[/unity] I think it is ok for a first try, good enough for prototyping anyway.
You're supposed to put .unity3d instead of .html inside unity tags. It looks good. If you're going to support Mecanim/Humanoid make sure you consider the important stuffs like Root Motion/In-Place.
[QUOTE=Pelf;42489231]And, of course, it's riddled with bugs and hardly works.[/QUOTE] And that was probably a good thing though because I replaced it with a much computationally simpler system and it [I]seems[/I] to be bug-free. What I was doing before is I was raycasting to every planet in the scene to find the closest planet, then I would get the planets position in the last fixed update and the current one, find the distance it moved (if it was a static planet the distance would be zero), raycast again to find the distance to the planet surface, use that distance to lerp a modifier variable to make a smooth transition between not being moved to being synced with the planets movement. And all of that would be done every FixedUpdate() so it seemed quite inefficient to me because I was doing a raycast plus one for each planet in the scene, plus a bunch of square-root calculations (which people say is pretty computationally heavy). And I had bugs where I would randomly teleport and I would still slide if I was on the outer side of the planet. Now, I have a sphere trigger surrounding the planet; when the player touches the trigger it sets the "active planet" to whatever planet the trigger is parented to. Then, every FixedUpdate() it will get the planets position in the last fixed update and the current one, find the distance it moved, then raycast down to the planet center to find the distance to the ground and use that distance to lerp the player movement modifier. Much less code and it seems overall more efficient. [editline]12th October 2013[/editline] Still need to make it rotate with the planet though.
Anybody want my first person controller? I made it because I really hate using unity's default First Person Controller and mouse look script. This script consolidates them and make it much less complicated and much more lightweight. Just make an empty gameobject with a character controller, put this script on it, and have a camera called "Camera" as a child of it. Any suggestions? [CODE] using UnityEngine; using System.Collections; public class BasePlayer : MonoBehaviour { public static BasePlayer instance; // Player movement and input. private CharacterController charController; private Camera playerCamera; private Vector3 moveInput; private Vector2 lookInput; public float moveSpeed = 10f; public float mouseSensitivity = 15f; // Initialize variables and such. public void Awake(){ instance = this; charController = GetComponent<CharacterController>(); playerCamera = transform.FindChild("Camera").GetComponent<Camera>(); } // Update the script. Called every frame. public void Update(){ Screen.lockCursor = true; moveUpdate(); lookUpdate(); } // Update the characters movement. public void moveUpdate(){ moveInput = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveInput = transform.TransformDirection(moveInput); moveInput *= moveSpeed; moveInput.y -= 2; moveInput *= Time.deltaTime; charController.Move(moveInput); } // Update the characters mouse look. public void lookUpdate(){ lookInput += new Vector2(Input.GetAxis("Mouse X") * mouseSensitivity, -Input.GetAxis("Mouse Y") * mouseSensitivity); lookInput = new Vector2(lookInput.x, Mathf.Clamp(lookInput.y, -70, 70)); transform.localRotation = Quaternion.Euler(new Vector3(0, lookInput.x, 0)); playerCamera.transform.localRotation = Quaternion.Euler(new Vector3(lookInput.y, 0, 0)); } } [/CODE] I also made it a singleton so you can just do BasePlayer.instance.giveItem() or whatever when I get to doing that.
[QUOTE=Duskling;42503203] I also made it a singleton so you can just do BasePlayer.instance.giveItem() or whatever when I get to doing that.[/QUOTE] Hi, can you explain me the basic of a basic intro of singleton? (No about code, just why) Example, which is the difference with static classes (the unity wiki doesn't say it too clearly and i can't make work both)
The humanoid rig in Mecanim ruins my animation. It seems like it locks movement of chest/stomach bones at the center so they can only rotate. I assume this is to keep the rig in the center so blend trees work properly. Really annoying. A generic rig works but there is no Foot IK. :( [editline]13th October 2013[/editline] Here is an example, the one in the front uses the humanoid rig and foot IK. [unity]https://dl.dropboxusercontent.com/u/41313766/Dont delete/ComparisonMecanim/ComparisonMecanim.unity3d[/unity]
[QUOTE=reevezy67;42506383]The humanoid rig in Mecanim ruins my animation. It seems like it locks movement of chest/stomach bones at the center so they can only rotate. I assume this is to keep the rig in the center so blend trees work properly. Really annoying.[/QUOTE] By default Mecanim will set one of its root axis to Center of Mass, I'm guessing this is the reason why it locks up like that. Are you referencing any running animations? Most of the running animations I saw made the hips as root, instead of making it going forward/backward. Go to mixamo.com and see their running animations (free to preview, costs money to buy) for reference.
I am just going to go with a generic rig for now, I can deal without IK for now. [editline]13th October 2013[/editline] Actually generic can still use Foot IK. What is the advantage of a humanoid rig then?
Animation retargeting, so you can share animations between different models that uses similar bone structure rather than making each model having the same animation built into it. Lets say you have a SWAT and a Soldier model, if you use generic, each model needs to have the same walk animation if you want to animate them. If you use Mecanim/Humanoid, you can have one walk animation, then retarget them to both SWAT and Soldier model.
[QUOTE=gonzalolog;42505535]Hi, can you explain me the basic of a basic intro of singleton? (No about code, just why) Example, which is the difference with static classes (the unity wiki doesn't say it too clearly and i can't make work both)[/QUOTE] Hey, sure I'll explain it a bit. I was confused at singletons at first also. They are kind of strange. So, a singleton is basically a class which has a static reference to itself. This means that wherever you are in your game, you can just type BasePlayer.instance.doThisFunction(); Now your probably thinking, okay, why not just use a static class for this? I can also access a static class anywhere. The reason you would use a singleton over a static class is that a singleton can be a gameobject ( it can extend monobehaivor ). The catch here is that a singleton can only be ONE object. In my case, it works because there is only one Player object present. A singleton can also implement an interface, but a static class cannot. Where would you use singletons over static classes? Well, say you wanted to have some sort of script that just holds data, such as the players money. Is it nessasary for it to be its own gameobject in the scene? If not, you can probably just use a static class. For something like a player, the player would need to be a gameobject in the scene, and you would want to access it anywhere, so a singleton would suffice. I'm sure there is more to it, and a better explanation, but this is how I understand. Hopefully I helped you out :)
[QUOTE=Duskling;42508534]Hey, sure I'll explain it a bit. I was confused at singletons at first also. They are kind of strange. So, a singleton is basically a class which has a static reference to itself. This means that wherever you are in your game, you can just type BasePlayer.instance.doThisFunction(); Now your probably thinking, okay, why not just use a static class for this? I can also access a static class anywhere. The reason you would use a singleton over a static class is that a singleton can be a gameobject ( it can extend monobehaivor ). The catch here is that a singleton can only be ONE object. In my case, it works because there is only one Player object present. A singleton can also implement an interface, but a static class cannot. Where would you use singletons over static classes? Well, say you wanted to have some sort of script that just holds data, such as the players money. Is it nessasary for it to be its own gameobject in the scene? If not, you can probably just use a static class. For something like a player, the player would need to be a gameobject in the scene, and you would want to access it anywhere, so a singleton would suffice. I'm sure there is more to it, and a better explanation, but this is how I understand. Hopefully I helped you out :)[/QUOTE] Thanks! Now is clear for me :D
I just tried out Unity and I have spent hours playing around with stuff. It's productive and fun to use. Now I have to practice modelling.
[QUOTE=gonzalolog;42510725]Thanks! Now is clear for me :D[/QUOTE] Keep in mind that you don't have to necessarily have only one gameobject of a certain type to use a singleton, the singleton will only run the function on the last object that was instantiated though, so say you have 3 enemies and they all have a static reference to themselves, the last one to be instantiated will associate itself to the static reference so any function you call from the singleton will use that object, which is fine if the functions you use for the singleton aren't object specific but you still want to keep them inside that class.
Sorry, you need to Log In to post a reply to this thread.