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 Neroner23 · Aug 13, 2012 at 04:51 PM · gamerpgthird-person

First rpg how to shoot arrows ?

Hi there. I am new to unity, so i really need help with start :/ My question is :

i have a character with bow and arrow's. I have animation when he shoots, but how to make the bow fly in direction ? It has to collide with object's it hits. What should be direction ? I would really like to make a croshair in front of my character, and every script, tutorial i have seen... it's not good enough.

Should i be working on javascript for arrow ? or make a C# file ?

Comment
Add comment · Show 2
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 Loius · Aug 13, 2012 at 04:59 PM 0
Share

Doesn't matter which language you use. Just use the one you're comfortable with.

If you search this site for 'arrow' you'll find a lot of questions very similar to this.

Short version - instantiate the arrow at the bow's position with the bow's rotation, give it a velocity, when it hits something, disable its movement.

avatar image Neroner23 · Aug 13, 2012 at 05:32 PM 0
Share

thanks for reply, but as i already told.. nothing helpfull is out there. i need help from point 0. I just found that a rigidbody should be attached to arrows joint, not the arrows its self ? am i right ?

7 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by subcod · Aug 13, 2012 at 06:22 PM

USE PHYSICS.RAYCASTHIT! SEARCH IT UP IN UNITY REFERENCES!

Comment
Add comment · Show 1 · 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 Loius · Aug 13, 2012 at 07:46 PM 0
Share

Dude calm down a bit.

avatar image
0

Answer by GlitchBait · Aug 13, 2012 at 06:29 PM

Start with basic objects and play with instantiate to achieve what exactly you're looking for.

Here is the basic Java code for instantiating an object from the object that holds this script.

Most/all of the term other users will suggest to you as solutions will be located in the Unity Script Reference. A reference, lexicon and bible. http://docs.unity3d.com/Documentation/ScriptReference/index.html

Good luck and best wishes! // Instantiate a rigidbody then set the velocity

var projectile : Rigidbody;

function Update () { // Ctrl was pressed, launch a projectile 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 * 10);
 }

}

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
avatar image
0

Answer by subcod · Aug 13, 2012 at 06:27 PM

//using javascript var Crosshair:Texture; var bullet:Transform; var mat:Material; function crossharRed()//This tells you if the bullit will hit or not

{

if(Physics.Raycast(bullet.gameObject.transform.position,Vector3.forward, distanceOfShot))

{

mat.mainTexture= Crosshair;

} }

function fire()

{

Instantiate(object.gameObject,object.gameObject.position,object.rotation) }

function Update()

{

object.gameObject.transform.position.x+=50; }

This is a basic code for what you are doing. I suggest you take a look at the Unity3d script reference if you have any questions or to trouble shoot any mistakes in the code. http://docs.unity3d.com/Documentation/ScriptReference/MeshRenderer.html

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
avatar image
0

Answer by subcod · Aug 13, 2012 at 06:23 PM

//using javascript var Crosshair:Texture; var bullet:Transform; var mat:Material; function crossharRed()//This tells you if the bullit will hit or not

{

if(Physics.Raycast(bullet.gameObject.transform.position,Vector3.forward, distanceOfShot))

{

mat.mainTexture= Crosshair;

} }

function fire()

{

Instantiate(object.gameObject,object.gameObject.position,object.rotation) }

function Update()

{

object.gameObject.transform.position.x+=50; }

This is a basic code for what you are doing. I suggest you take a look at the Unity3d script reference if you have any questions or to trouble shoot any mistakes in the code. http://docs.unity3d.com/Documentation/ScriptReference/MeshRenderer.html

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
avatar image
0

Answer by tw1st3d · Aug 13, 2012 at 07:49 PM

 function Update() {
     if(Input.GetButtonDown("Fire1")) {
      arrow.useGravity = false;
         var instance : Rigidbody = Instantiate(arrow, muzzlePoint.position, Quaternion.identity);
         instance.velocity = muzzlePoint.forward * 100;
     }
 }
Comment
Add comment · Show 3 · 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 Loius · Aug 13, 2012 at 07:59 PM 0
Share

You're accessing arrow before it's set, you're disabling gravity on it (?), you're not giving it a meaningful rotation, and you've got 'muzzle' stuff going on. Not that varnames do anything to logic but it's best not to confuse the programmer.

avatar image tw1st3d · Aug 13, 2012 at 08:04 PM 0
Share

I'm sure if he's developing an RPG, he'd have a variable set for arrow, and I wouldn't be required to do so for him. Therefore, setting the gravity for a variable that he should already have would cause no problem.

avatar image Loius · Aug 13, 2012 at 08:07 PM 0
Share

Whoops, saw 'arrow' and assumed that would be the instantiated object. $$anonymous$$y dumb.

  • 1
  • 2
  • ›

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Hard question about 2d sprites in 3d world 2 Answers

thrid person help 1 Answer

How to go about making a huge game world 2 Answers

How to destroy a certain object with another certain object? 1 Answer

c# Unexpected symbol 'foreach' 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