Instantiating cubes at runtime, align them
I'm making a little game demo where I'm playing around with some ideas. At the moment I'm allowing my player to build his own house in a way very similar to Minecraft. A cube prefab serves as the...
View ArticleRaycast no hit when depends on input
I'm trying to cast a ray to check for collision when "W" is pressed. I figured out how it should work but I can't figure out why it's working in my first case and not in the second. 1) In this case...
View ArticleHiding objects between my character and camera, how to show them again when...
I'm using the following code to hide objects between the camera and my player: private void Update() { Debug.DrawRay(this.transform.position, (this._target.transform.position -...
View ArticleUnity unexplicably freezes on a very simple procedure
I'm working on the very beginnings of a random level generator. I'm running this code: using UnityEngine; using System.Collections; public class Generator : MonoBehaviour { public GameObject rock; //...
View ArticleOnCollisionEnter problems
My apologies for asking such a simple question. I have this code attached to my character (FPS character controller): void OnCollisionEnter(Collision c) { print("hello"); } I've attached a RigidBody to...
View ArticleCan't get ENTER key working
I've been trying to get the Enter key working: void Update () { if (Input.GetKeyDown("enter")) { print ("enter pressed"); } } I also tried `Input.GetKeyDown(Keycode.Return)` I read the manual and other...
View ArticleCan't Translate and Rotate at same time
I'm writing my own character controller that uses a rigidbody. I'm getting stuck on something weird. This is my code (variable declarations not included): void Start() { myNormal = transform.up;...
View ArticleConverting this for loop to C#
I'm trying to convert this particular for loop from JS to C#. for (var t: float = 0.0; t < 1.0; ) { t += Time.deltaTime; transform.position = Vector3.Lerp(orgPos, dstPos, t); transform.rotation =...
View ArticleScreen.lockCursor mystery?
I'm using this simple code on my custom FPS character controller: void Start() { // Lock Cursor Screen.lockCursor = true; } I just want the mouse cursor to stay frozen where it is (ie: always in the...
View ArticleSet RigidBody Transform y to the Characters Transform y
I'm writing a script for my character to pick up objects. I almost have it nailed down but at the moment when the character "picks" the object it stays on the floor, and just gets dragged around as the...
View ArticleCreating this light effect
How can I create this light effect? I have little experience with graphics how could I create this light effect? http://misslineage2.com/media/images/pics/popup2.jpg
View ArticleSwing an object back and forth
I'm trying to write a piece of code that swings an object forward and backwards. Eventually it will be for swinging a close combat weapon in an FPS. IEnumerator swing() { Vector3 orgPosition =...
View ArticleCharacter stand straight
I've implemented a spell casting system where my character always faces where he is casting. This some times makes his y rotation change when he's casting upwards (flying enemy etc). I would like to...
View ArticleIs character facing in the direction of camera?
How could I check if the character is facing in the direction of the camera or away from it?
View ArticleControllerColliderHit, two objects, takes wrong one
I'm using this code to detect the collision between my player and "Cloud" gameObject. Funnily enough this code: function OnControllerColliderHit(hit : ControllerColliderHit) { if...
View ArticleHow to get NetworkViewID and GameObject attached to NetworkViewID
I can't seem to find reliable information about this. I have a Network View component attached to a game object. How can I access this Game Objects NetworkViewID from code? I have tried...
View ArticleDrawing a box with mouse dragged on screen
When a user clicks mouse0 I set a Vector2 orgBoxPos = Input.mousePosition; While he is holding down mouse0, I constantly update Vector2 endBoxPos = Input.mousePosition; I then try this to draw this box...
View ArticleIf button held 3 seconds do something
I'm trying to do a Crouch/Lay down system: 1) Press C => crouch 2) Hold C for 3 seconds => lay down The logical way to do this seemed to be to use a timer: if (Input.GetButtonDown ("Crouch")) {...
View ArticleCharacter Controller/Motor Ground Delta
Is there a way to set a distance between the Character Controller/Motor and the ground? My ground is quite wobbly and I would like to avoid shaking the character and the camera by having the character...
View ArticleVoxel Lighting
I'm working on a Voxel project for fun and learning. I've been reading up a lot on how this is done and have implemented a simple Voxel map in my project. My question is about the lighting. I've read...
View Article