Tag Info

New answers tagged

0

Try adding an if statement saying if neither of the axis are equal to zero then change the rotation, this would eliminate facing forwards when there is 0 on each axis. if(direction != Vector3.zero) {Quaternion rotation = Quaternion.LookRotation(direction, Vector3.up); transform.rotation = rotation; } Hope this helped.


0

For game maker you can use this tutorial


0

It is not just a rectangle/rectangle test. It is also a dot product test to determine which side of the slope line the other object is on. For this you will need to initialize the 2 end points of your slope. This becomes a line segment and the corners of your slope's collision rect. So your slope and rect both share point A & B. The algorithm gos like ...


0

Try adding effect.Alpha = 1f; The alpha channel was probably premultiplied (check the texture properties in your content section).


0

It looks like time scaling could be an issue here: you scale gravity by Time.deltaTime and apply that to the y axis of the movement vector. You then take that vector and scale it by Time.deltaTime. This means that the y axis has been scaled twice. Given that there is usually very little time between Updates, you'll probably find that this means ...


0

Take a Look at Texture2D.GetPixel You can find the contact point on the collider and then map that to the specific point on the texture.


0

My problem here was not reading the RPC calls section of http://docs.unity3d.com/Manual/UNetActions.html properly. "They can be sent from any server object with a NetworkIdentity that has been spawned." When I had the client object reading in the locations become a spawned object under Registered Spawnable Prefabs (under Spawn Info, under Network Manager ...


0

You can use the Update method to update the current volume. private void Update() { VolumeControl(slider.value); } And use the OnApplicationQuit method to save your current volume to the PlayerPrefs. Receiving the saved volume from the PlayerPrefs in the Awake method can be done like in your code snippet, but without the PlayerPrefs.Save statement.


0

Managed to fix this by using Viewports when drawing the Rectangles / Cameras GraphicsDevice.Viewport = new Viewport(_level); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, _camera.ViewMatrix); DrawLevelTiles(); spriteBatch.End(); GraphicsDevice.Viewport = ...


1

I think you might be overcomplicating things - why not just set the "origin" of the hook to new Vector2(0, hookTexture.Height / 2) If you simply draw it like this: spriteBatch.Draw(hookTexture, position, null, Color.White, rotation, new Vector2(0, hookTexture.Height / 2), 1.0f, SpriteEffects.None, 0.0f); That way the hook is drawn and rotated around ...


2

One way to do this, is to draw your text 2 times in a different color at specific offsets. For example: public static void DrawText(SpriteBatch spritebatch, SpriteFont font, string text, Color backColor, Color frontColor, float scale, Vector2 position) { Vector2 origin = Vector2.Zero; spriteBatch.DrawString(font, text, position + ...


0

In the past, I've attached a script to the music AudioSource that sets ignoreListenerVolume, to bypass the main volume controls. A crude example to get the point across: void Start() { AudioSource music = GetComponent<AudioSource>(); music.ignoreListenerVolume = true; //you can manage the music's volume directly, now music.volume *= ...


0

Only change the rotation whenever your distance is above a certain delta. Also center your sprite, right now you're using the top-left corner of the sprite.


1

http://answers.unity3d.com/questions/16603/is-there-a-global-volume-setting.html Use the slider's value to determine the AudioListener.volume static field. http://docs.unity3d.com/ScriptReference/AudioListener-volume.html It is between 0 and 1. You can get a normalised( between 0 and 1 ) value from the slider using Slider.normalizedValue.


2

Yes, you can do this with no expensive trig at all. Steps: Find the distance between the 2 circles. Find the combined radius between the 2 circles. Subtract the distance from the combined radius to get the depth of the penetration. Multiply the direction between the circles by the penetration depth. I.e.: Circle c1; Circle c2; float Distance = ...


0

using UnityEngine; using UnityEngine.UI; public class SliderSaver : MonoBehaviour { public Slider slider; void Awake () { slider.Value = PlayerPrefs.GetFloat ("Slider value"); } public void OnSliderChange (float newValue) { PlayerPrefs.SetFloat ("Slider value", newValue); } } This sets the slider's value in ...


0

That one is easy and, yes, even after many years as a programmer I stumble upon this kind of situation. In SpriteChange you change values held by your levelManager: levelManager.highlight = "none"; levelManager.highlightDirection = "none"; levelManager.changelight = "none"; levelManager.changelightDirection = "none"; However, in your else parts of your ...


0

One approach is to set ignoreListenerPause on the AudioSource for your music and then set a mute on the overall game using AudioListener.pause. Now AudioListener.pause will mute everything except your music, while you can still mute that audio source directly. I take that approach in the audio chapter of my book (see my profile).


1

This is not directly possible in Unity because: There is no difference between sound and music for the Audio Sources The volume of every Audio Source is independent of eachother You will need to search for the Audio Sources in your local scene to iterate through them with Object.FindObjectsOfType. var audioSources = ...


0

If you have maps that contain thousands of blocks, updating and drawing them all isn't efficient, and you lose a lot of valuable processing time. All you need to do is just draw what is in the viewport. Update blocks that are in the viewport as well, but make sure to update any moving blocks as well. Say you have a camera and a 2-dimensional array of ...


0

I believe your problem here is that you are clearing out your list in OnBeforeSerialize() and recreating it in onAfterDeserialized(). I think your problem is that you are expecting OnAfterDeserialized() to be called after OnBeforeSerialize() and after you have added a new item to your list in the custom inspector (a reasonable assumption). However this does ...


1

Both technics are ok. It's not that consuming to render more than it needs on modern devices, and the half of clipping/culling work made by graphical library itself. Most common technic is rendering chunks, such as rooms.


1

Your code has some serious issues. First of all, in games, you generally don't want to be moving objects on the screen by a flat amount per frame, because then the frame rate can make you go faster or slower, which is not a good thing. The way you want to be moving your objects is with delta time, which is the elapsed time between this and the previous ...


0

Try to change the tris for loop to ++ instead of +=3: for(int i = 0; i < m.vertices.Length-3; i++){ tris.Add(i+2); tris.Add(i+1); tris.Add(i); } Each 2 neighboring triangles have 2 shared vertices, so += 3 would skip 2 triangles each time.


0

Make methods that seals each of the stages you have(possibly make them into a class), and a infinite loop is will be running on the Start() function along with your storyline. Your Story class public void stage_1() { int choice = 0; //Do something at your stage if(choice == 1) stage_2(); else if(choice == 2) stage_4(); ...


3

If you don't specify an f at the end of a decimal value in C#, it's assumed to be of type double. To preserve precision, double does not implicitly cast to float. So because of the .5 you put in the y (rather than the -9.5f in the tutorial's code), your examples have the signatures: new Vector3(int, double, int) new Vector3(int, double, float) ...both of ...


1

If I understand correctly, what you want to compute is the spline's radius of curvature at each point. Then you want to compare that value to an agent's turning radius to determine if the agent will leave the track there. [1] To do this, you need to calculateR(s)as you see here: https://en.wikipedia.org/wiki/Curvature (under "Curvature of plane curves" > ...


0

My partial solution to your "brick wall" is... a Node. Lots of nodes. Something along the line of.... First node(Head node): NodeID:1 Message:"You see a path on the left leading to a gloomy forest. You could taste the hint of the sea from the wind blowing from the right. Options: -Option: Title:"Go Left" TargetNodeID:2 -Option: Title:Go Right" ...


0

This is a super broad question. I have no idea what you want to do with the game, the only thing I can say is everything needs to be contained within a while 1 infinite loop. There's not a lot of advice to give besides that. Just don't think about it too much, actually go start programming the game and you will realize what you need as you go. I mean it's ...


1

finicky and broken feeling This should probably just be the issue because you're using FixedUpdate() instead of Update(), thus the groundcheck / jumpcheck, doesn't happen every frame, but every physics update, try changing that and it should be fixed.


1

Yes, you are stuck with needing a child object for each individual sprite that makes up your characters. It's not as tricky as it sounds though. You can create one generic "Humanoid Character" prefab with child objects like "Body", "Helmet", "Weapon", etc. You can then use this prefab for both PC and NPCs. Layers Pay attention to Sprites layering. Almost ...


-1

If you create a single material for the sprites, and they use a spritesheet, they should be batched into a single draw call automatically. :) From the Unity3D answer hub (kindly answered by ivomarel): Yes, make sure that the sprites are in the same atlas. When you select a sprite, (Texture type should be sprite), look at the inspector and choose ...


0

There is only 1 optimization you need to implement: Vector2 Min, Max; Min = poly.Vertices[0]; Max = poly.Vertices[0]; for (int i = 1; i < poly.Vertices.Length; i++) { Vector2 Vertex = poly.Vertices[i]; if (Vertex.x < Min.x) { Min.x = Vertex.x; } else if (Vertex.x > Max.x) { Max.x = Vertex.x; } if ...


1

Please, at all cost, avoid using vector2(or 3 or 4 for that matter).Distance(). If you can, use DistanceSquared() instead. To get the actual distance, XNA uses the pythagorean theorem, which ultimately means that it needs to use the square root function. This is a relatively slow function. So use this instead: for (int x = 0; x < map.GetLength(0); x++) ...


2

This bit: void Update() { StartCoroutine (TurretWaves()); } Once you start a coroutine, it will continue processing automatically. If you call StartCoroutine twice, you will launch two independent coroutines. If you call StartCoroutine once per frame, you will start a new, fully independent coroutine on every frame. By the time your game finishes ...


0

Usualy it's a good practise to use StartCoroutine into the Start(), you're "starting" a coroutine on every update!! Here can find some examples on using StartCoroutine. using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Start() { print("Starting " + Time.time); ...


0

The asset bundle system does not automatically remove anything nor does it load dependencies automatically. Dependencies are included in asset bundles automatically, but actually exist in each asset bundle that depends on them, unless you manually removed them. For example, if you have a 2 different player models, Hero1 and Hero2. They both share a Gun ...


0

The asset bundle dependencies are not processed in the "load", but when the asset bundle is created. Unity basically loads the entire asset bundle in at at a time, and then instantiates particular assets inside the asset bundle. To remove asset bundle dependencies at build time, take a look at the AssetBundle.PushAssetDependencies function. Any assets that ...


-1

3D objects still have an X and Z coordinate. The only thing you have to do to make it isometric in 3D settings is to ensure the Y value for all the tile objects are the same. Generally we set this to 0. Put your camera wherever you like the angle, and voila! I hope this clears things up.


0

From your example I can tell you're making a "connect the pipes" type game. You have two possible approaches here: You can hard code each level, testing the map array for a specific total state, making sure that A2, A3, and A4 are all orange. You can program a pathing algorithm to test if there is a path between the two colors. The second option will be ...


-1

if you haven't already gotten this figured out, a simple way to do it without complicated path-finding is to check the position of all of the enemies vs yours. If the enemies are below you position, move them up. If they are too far to the left, move them right. It's as simple as that. Example: foreach (Enemy enemy in enemies) if(enemy.x > player.x) ...


0

You are forgetting to dispose your game object. [STAThread] static void Main() { using (Game1 game = new Game1()) game.Run(); using (Game1 game = new Game1()) game.Run(); }


0

Here is my unity path finding using waypoints (nodes linked each others), recursion and linq: ... using System.Collections; using System.Collections.Generic; using System.Linq; ... public List<Waypoint> aStar( Waypoint goal,Waypoint nx, List<Waypoint> visited){ if( visited.Contains(nx)){ return null; } else { ...


1

You might be able to side-step using rectangles altogether. For a top-down shooter you could use bounding circles instead of boxes. Checking collision between circles is much easier and faster than checking collision between non-axis-aligned bounding boxes (just check if the distance squared is less than the sum of the radii squared) and you don't need to ...


1

You wrote Material.GetTextureOffset ("_MainTex"); in the Start() method. It should be material.GetTextureOffset ("_MainTex");.


0

My solution to this problem would be to simply use OnColliderEnter: private void OnColliderEnter(Collision collision) { collision.rigidbody.AddExplosionForce(power, transform.position, radius, 0); collision.gameObject.SendMessage("Damager", Damage, SendMessageOptions.DontRequireReceiver); } This problem solution assumes that the slash execution is ...


2

As per the documentation, [Command] and [ClientRpc] should be in a NetworkBehaviour, not in a MonoBehaviour. NetworkBehaviour's must be spawned using NetworkServer.Spawn(). Moreover you should use a NetworkClient Object to connect to the Server. Take a look at this Note: As of Unity 5.1 offline documentation is not up to date. Even some aspects of online ...


0

Expanding upon Anthony Ngo's answer As of Unity 5.1 you can simply do it in the editor: Source: http://unity3d.com/unity/whats-new/unity-5.1 To get to that part you can probably do Ctrl + F then type rigidbody. Your browser should then highlight that part.


4

First of all, since you're working in 2D, you'll want to use the type RigidbodyConstraints2D as opposed to just RigidbodyConstraints. Secondly, you can't freeze the y rotation on 2D rigidbodies, only in the z axis, which you can do by saying: pos = RigidbodyConstraints2D.FreezeRotation; Equally, you could just set it in the inspector with the gameobject ...


1

Have a look at the online API. It states that the function requires an argument of type Collider, which is what you're missing. It should be: void OnTriggerExit(Collider other) Not: void OnTriggerExit() Another note, make sure one of the objects colliding have a rigidbody, Unity requires it to detect collisions.



Top 50 recent answers are included