Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DTJ Productions · Apr 26, 2010 at 11:01 PM · javascriptfpsshooting

Player cannot shoot

Hey, I'm trying to make my FPS character shoot a bullet but it is not working, their are no errors or anything here is my moving and shooting script

/

/Moving around var speed = 5.0; var rotateSpeed = 3.0; var HealthControl;

var isWalking: boolean;

//shooting var bullitPrefab:Transform; var parBullitHit:Transform; var bullit;

//dying private var dead = false;

//Getting hit var tumbleSpeed = 800; var decreaseTime = 0.01; var decayTime = 0.01; static var gotHit = false; private var backup = [tumbleSpeed, decreaseTime, decayTime];

//function OnControllerColliderHit(hit : ControllerColliderHit) function OnTriggerEnter( hit : Collider ) { if(hit.gameObject.tag == "fireBall") { dead = true; //substract life here HealthControl.LIVES -= 1; Destroy(hit.gameObject); }

 if(hit.gameObject.tag == "enemyProjectile")
 {
     gotHit = true;
 }   

}

function Update () { var controller : CharacterController = GetComponent(CharacterController); transform.Rotate(0, Input.GetAxis ("Horizontal") rotateSpeed, 0); var forward = transform.TransformDirection(Vector3.forward); var curSpeed = speed Input.GetAxis ("Vertical"); controller.SimpleMove(forward * curSpeed);

if(Input.GetButton("Mouse")) {

var bullitPrefab = Instantiate(bullitPrefab, transform.Find("Spawnpoint").transform.position, Quaternion.identity);

bullitPrefab.rigidbody.AddForce(transform.forward * 5000); }

 if(Input.GetButtonDown("Jump"))

{ var parBullitHit = Instantiate(parBullitHit, transform.Find("spawnpoint").transform.position, Quaternion.identity);

parBullitHit.rigidbody.AddForce(transform.forward * 1500);

} }

function LateUpdate() { if(dead) {

     transform.position = Vector3(0, 1.753925, -2.850807);
     gameObject.Find("Main Camera"). transform.position = Vector3(0.2640705, 45.65512, -2.402526);
     dead = false;
 }

the "mouse" part is what I named the left click button.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by e-bonneville · Apr 26, 2010 at 11:18 PM

Just use this:

// Put this at the top of your script var projectile : Rigidbody; var speed = 10;

function Update () { // Put this in your update function if (Input.GetButtonDown("Fire1")) {

 // Instantiate the projectile at the position and rotation of this transform
 var clone : Rigidbody;
 clone = Instantiate(projectile, transform.position, transform.rotation);

 // Give the cloned object an initial velocity along the current
 // object's Z axis
 clone.velocity = transform.TransformDirection (Vector3.forward * speed);
 }

}

You're instantiating a projectile at wherever 'spawnpoint' is, which, I'm assuming, is where you spawn? If that's the case, that's why your script isn't working.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DTJ Productions · Apr 27, 2010 at 03:19 AM 0
Share

Ah thanks but the prob is as you see in my script I already have a speed var, and thats for my characters speed. How do I make two? One for running and one for shooting.

avatar image DTJ Productions · Apr 27, 2010 at 03:21 AM 0
Share

Oh and it is weird the bullets are not shooting in curtain areas, and also the more I move left the more the bullets spawn from the left.

avatar image e-bonneville · Apr 27, 2010 at 11:50 AM 0
Share

Well, to make two speed vars, name your bullet speed bulSpeed or something of that sort. Unity figures out the physX for you, don't worry about adding the player's running speed to the bullet speed or anything like that.

avatar image e-bonneville · Apr 27, 2010 at 11:51 AM 0
Share

Also, put that script on a separate file and attach it either to your camera or a point you want your bullets to spawn from, like in front of your gun or wherever your gun should be.

avatar image
0

Answer by Kroltan · Apr 04, 2011 at 09:28 PM

You can use Raycasts and a delay based on the ray distance to make bullets. It is more appropriate because bullets generally have a ridiculous speed and a small size and physics don't update in a perfect manner. they have "holes" in the path.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Shooting only once, returning boolean as false 2 Answers

Need help... Start Button no longer working!!!!! 0 Answers

fps shooting in the direction of character main cam 1 Answer

Clones of enemies will not shoot 0 Answers

How to change the sensitivity on right click (when zoomed in) 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges