Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 MC HALO · May 09, 2011 at 11:22 AM · instantiatefpsshoot

FPS shooting Help!

Hi guys. i was wondering if someone could help me out with something. Basically i just created simple lines of code which instantiate bullets from my gun. but the problem is when i run the game and shoot straight it shoots fine the bullets go straight. But if i start moving my gun up and down the bullets react funny. Basically if i look up and shoot the bullets start to shoot but fall down they dont shoot straight, and if i am facing down the bullets shoot and go up. now that is unrealistic to me. can some one please show me how i can shoot out of a raycast instead of instantiating from a spawn point in front of the gun. this way the bullets will fallow the ray in a straight direction and then fall later on.

all i did was i added the unity fps control system and in the FPSInputController i added the instantiate bullet code. how can i do this using a ray cast instead. Thank you very very much in advance MCHALO looking forward to your guys replies thanks

Here is the script:

private var motor : CharacterMotor; var Bullet_Shoot: Transform; var BulletSpeed : float; // Use this for initialization function Awake () { motor = GetComponent(CharacterMotor); //Bullit_Shoot = transform; }

function Start (){

 BullitSpeed = 20000;


}

// Update is called once per frame function Update () { // Get the input vector from kayboard or analog stick var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

 if (directionVector != Vector3.zero) {
     // Get the length of the directon vector and then normalize it
     // Dividing by the length is cheaper than normalizing when we already have the length anyway
     var directionLength = directionVector.magnitude;
     directionVector = directionVector / directionLength;

     // Make sure the length is no bigger than 1
     directionLength = Mathf.Min(1, directionLength);

     // Make the input vector more sensitive towards the extremes and less sensitive in the middle
     // This makes it easier to control slow speeds when using analog sticks
     directionLength = directionLength * directionLength;

     // Multiply the normalized direction vector by the modified length
     directionVector = directionVector * directionLength;
 }
 if(Input.GetKey(KeyCode.Z)){


var Bullet = Instantiate(Bullet_Shoot, GameObject.Find("Bullet _Shoot").transform.position, Quaternion.identity); Bullit.rigidbody.AddForce(transform.forward BulletSpeed Time.deltaTime); print("HHHHH");

} // Apply the direction to the CharacterMotor motor.inputMoveDirection = transform.rotation * directionVector; motor.inputJump = Input.GetButton("Jump"); }

// Require a character controller to be attached to the same game object @script RequireComponent (CharacterMotor) @script AddComponentMenu ("Character/FPS Input Controller")

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dave 11 · May 09, 2011 at 12:28 PM

http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html

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 MC HALO · May 09, 2011 at 12:43 PM 0
Share

i know how to ray cast but how do i instantiate it co$$anonymous$$g from the ray itself ?

avatar image FLASHDENMARK · May 09, 2011 at 01:05 PM 0
Share

You want to instantiate a raycast form a ray?

avatar image MC HALO · May 09, 2011 at 01:39 PM 0
Share

basically at the moment i press a key and then it instantiates the bullet, and adds force to it. But the problem is when i shoot up the bullets fall start to fall down because rigidboady is applied to them. and if i face down and shoot the bullets dont shoot down. what i want is i created a blank object where the bullet instantiates from.n But what i want is on that blank object an ray cast shooting out straight. i then need to some how make the bullets instantiate from the bullet re-spawn but this time it should shoot from the ray in a straight line.if this is confusing please tell me

avatar image MC HALO · May 09, 2011 at 01:40 PM 0
Share

then i will update the answer with images on what i am talking about :)

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 with a locked camera position 1 Answer

continuous shooting 1 Answer

Make multiple Projectiles move at the same Time... 0 Answers

FPS Kit Version 2.0 1 Answer

Object Instantiating to many objects 1 Answer


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