|
Trying to make it so i can just use the First person controller prefab as a basic FPS controller to just get an idea of how my game will work. I just started this stuff a couple days ago and know barely any java script, but thanks to Tornado Twins got a good idea of what to do. I've got the script down and it shoots fine, I added the spawn point of the bullets in front of the player and dropped it in the Controller Prefab, now if i move the camera left or right, the spawn point does to and i can turn my gun, but if i try to look up or down the spawn point stays at the same height and doesnt rotate, any idea how to fix it? heres the parts i added to the FPSWalker script: (note i took out a lot of the script, just parts i manually put in)
{ var bullit = Instantiate(bullitPrefab, GameObject.Find("SpawnPointTwo").transform.position, Quaternion.identity); bullit.rigidbody.AddForce(transform.forward * 2000); } if(Input.GetButtonDown("Fire2")) { var bullits = Instantiate(bulletPrefab, GameObject.Find("SpawnPointTwo").transform.position, Quaternion.identity); bullits.rigidbody.AddForce(transform.forward * 8000); } I put this right after the jump button, outside of the if on ground part. (i also added the variables on top so thats fine too). I dont know if i should even attempt to attach this in the mouse move script and see if that fixes it or is that not the problem? please help if you can :)
(comments are locked)
|
|
You use the FPS Walker as reference for your shooting direction. The capsule which represents your player is rotated horizontally by the mouse-look script attached to the Controller. YOu will find the main camera as a child of your First Person Controller. I would copy the above code and put it into a separate script. Putting this code into any FPS Walker or Mouse Look script will just make it very messy. Attach this new script to the Main camera and you should be all set. The main camera has another mouse look script attached which is responsible for the vertical rotation. That's why your current solution ignored the vertical rotation, because the FPS capsule doesn't care about any vertical rotation, it's the main camera which is repsonsible for this rotation. thank you that worked very easy. hmm guess i have another small question, is there a very easy way to make the mouse invisible when its on the screen (in the end i want it to re appear when you hit enter so you can mess with inventory and stuff, but for now lets just tackle invisibilty)
Feb 15 '10 at 03:26 AM
Adam Bruns
Screen.showCursor = false; should do
Feb 15 '10 at 03:34 AM
Sebas
thanks Sebas it worked
Feb 15 '10 at 07:49 AM
Adam Bruns
(comments are locked)
|
|
Try this! var BulletPrefab:Transform; var force : float = 2000; function Update() { if(Input.GetButtonDown("Fire1")) { var bullet = Instantiate(BulletPrefab, GameObject.Find("spawnPoint").transform.position, GameObject.Find("Gun").transform.rotation); bullet.rigidbody.AddForce(bullet.transform.forward * force); } }
(comments are locked)
|
|
Put the script on the camera that's a child of the controller instead of the controller itself, since the camera looks up and down but the controller doesn't (and, in fact, can't). hmm I went to look at that (and remember as i said i know very very basic java script) and does void Update work like function Update?
Feb 15 '10 at 03:18 AM
Adam Bruns
just put the above code into the function Update() {} of a new JS script and proceed like Eric suggested. That should do the trick.
Feb 15 '10 at 03:25 AM
Sebas
(comments are locked)
|
