x


First person controller Prefab Question

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)

if(Input.GetButtonDown("Fire1"))

{

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 :)

more ▼

asked Feb 15 '10 at 03:10 AM

Adam Bruns gravatar image

Adam Bruns
274 24 27 38

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered Feb 15 '10 at 03:20 AM

Sebas gravatar image

Sebas
4k 12 18 45

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)
10|3000 characters needed characters left

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);

} }

more ▼

answered Apr 15 '12 at 11:01 PM

Gareth.leslie gravatar image

Gareth.leslie
0

(comments are locked)
10|3000 characters needed characters left

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).

more ▼

answered Feb 15 '10 at 03:13 AM

Eric5h5 gravatar image

Eric5h5
80.1k 41 132 519

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)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1251
x176

asked: Feb 15 '10 at 03:10 AM

Seen: 3869 times

Last Updated: Apr 15 '12 at 11:01 PM