Hey guys I'm currently working on a car game (http://forum.unity3d.com/threads/help-with-3d-car-game.299031/#post-1980207) if you want a description, I wanted to know if anyone has a better script for a cube to move forward in the direction of the player, I coded one , but the cube follows the player whenever the player moves, which is not what I want , I just want it to move in a straight line. ( I also don't want the misconception that I want people telling me everything)
jtsmith1287 Thanks a lot , but I don't know if it would work. I re-scripted the cube movement and it's moving fine , onl Code (CSharp): using UnityEngine; using System.Collections; public class MoveFoward : MonoBehaviour { public float moveSpeed = 10f; // Use this for initialization void Start () { } // Update is called once per frame void Update () { transform.position += transform.forward * Time.deltaTime * moveSpeed; } } y thing is it's moving backwards. Here is my code if it helps.
To elaborate on @jtsmith1287's point, the standard convention in Unity 3D is for "forward" to mean "in the local +Z direction". Objects should generally be modeled and imported so that this is the case, i.e., the front face of whatever it is, is facing down the +Z axis. Then transform.forward will match what you think of as "forward" for your object. If you have a model where this is not the case, you can either fix the model; or stick it inside a GameObject, rotated so that +Z is forward, and do all your transforms on that GameObject; or just live with the fact that your object's forward direction doesn't match transform.forward, and adjust your code accordingly.
@jtsmith1287 and @JoeStrout I've fixed it , I used the rotate option and rotated it all the way around like jt said and I got it to move foward.
I also saw a lot of other threads on this problem , but does anyone know how you spawn objects, like I know how to create spawn points , but how do you actually spawn the cube?
You either use GameObject.CreatePrimitive, or you instantiate a prefab. Read about both approaches here.
Here is my code for my spawn points, I tried to code without looking anything up . Tell me my errors please. Also Unity gives me the infamous error CS8025 and CS1525 , so if you can help that would be great. Code (CSharp): using UnityEngine; using System.Collections; public class Spawn : MonoBehaviour { public GameObject Cube; public float spawnTime = 3f; public Transform [] spawnPoints; // Use this for initialization void Start () { InvokeRepeating ("Spawn", spawnTime, spawnTime); } // Update is called once per frame void Update () { UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Vector3, UnityEngine.Quaternion) } { { }
http://docs.unity3d.com/ScriptReference/MonoBehaviour.InvokeRepeating.html http://docs.unity3d.com/ScriptReference/Object.Instantiate.html I would make sure you thoroughly understand the above documentation before proceeding. It might lead you down a rabbit trail of learning (which is a good thing), but you'll get it sooner or later and it'll save a TON of headache. Fighting with 1 line of code you don't understand is way worse than fighting with 10 lines you do understand.
Yeah... don't do that. Have the documentation open at all times, and refer to it frequently as you code.
Ha. I didn't even see that at first. Ya don't feel like you're "winning" if you don't have to look at documentation. The guy that taught me my first language had to double check the docs to make sure he was right on things he hadn't done in a while. I have 3 computer monitors. One for unity, one for visual studio, and the other? You guessed it. A browser open with the manual, tutorials, forums, docs, etc. Usually by the end of the night I have 20 tabs open as I've looked up various things. There's a ridiculous amount to know with programming, and you'll likely never know it all. If you wanna code, you have to also wanna read a lot. Heck I just bought a AI book and these last several nights I've just been sitting here reading my book instead of coding. Read read read. Then read. Read more, read read... anyway. My point is: you're not less of a programmer for checking docs. PS Spell checker didn't put a squiggly line on 'wanna', and that is interesting to me.