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 Unity_Mike2012 · Aug 11, 2012 at 11:50 PM · mouse cursormouse controlcrosshairs

How do you create crosshairs that are controlled by the cursor/mouse similar to AngryBots?

Firstly, I am completely new to game design and I'm not very savvy with Javascript or any other programming utility. I have basically been just copy and pasting everything I've found so far, which is fine. But I would really like to develop a custom crosshair/target script that behaves like the player's cursor in AngryBots, or also like Super Mario Galaxy 2's Yoshi tongue. In other words, the mouse becomes the cursor embedded into the game, and acts as the firing trajectory's target. I'm planning on making a game that involves the use of a tongue like Yoshi's, where you aim at a point on the screen, press the fire button, and a tongue shoots out then snaps back in. If someone could please point me in the right direction that would be great. Thanks very much everyone!

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

5 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by drak0 · Aug 12, 2012 at 09:51 AM

The FPS tutorial

It will help, just don't copy paste everything.If I were to just give you the script or the methods to use, you wouldn't get a thing.Good luck, and if you don't understand some method used, look it up here

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 Unity_Mike2012 · Aug 13, 2012 at 04:37 AM

drak0,

Thank you for the feedback, I'll go through the tutorial. My concern though is that I might not find exactly what I am looking for, and spend a lot of time learning things that I don't necessarily need to learn right away because this is an FPS tutorial. Shooter games aren't what I'm interested in developing. The game I would like to create, was envisioned as third person, so I've been trying to find something in regards to a Zelda-oriented gamer interface. In other words, the action would be third person based, and utilizes at least two different cameras with two different scripts, one for the character, and one for attack targeting, similar to that of Zelda. However, I am also not sure how to really model the actor of the game because the more I play around with Unity the more I am finding that the tongue of the actor (frog) would have to be modeled separately, and act as a child object to the character object. Again, I'm very new to the fundamentals of Unity, Modeling and Rigging, and if there is anything out there that someone knows about regarding third person cameras like Zelda, that would be great. I'm hoping to make this game, and then a blog to host the game for the public to play. Anyone that can give me some tips will be credited in the development of the game. Thanks again, drak0 I really appreciate your advice. Thanks everyone!

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 drak0 · Aug 13, 2012 at 05:10 AM

Ok, I understand, but some of the things explained there are not only for FPS games, even more, when you understand how they work together, you can adapt them for your needs.For 3rd person, try this .

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 Unity_Mike2012 · Aug 13, 2012 at 06:52 PM 0
Share

I have a question regarding something I came across in the FPS tutorial. When I made the rocket in Part 2 of the tutorial, I "eye-ball" aligned it to be roughly close to concentric with the diameter of the barrel it should launch from. However, when playing the game I noticed the rocket does not fire from the transform position I aligned it to. So I looked at the script for the rocket launcher called "Rocket Launcher.js" and this is what I noticed:

             // create a new projectile, use the same position and rotation as the Launcher.

var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position,
transform.rotation);

Now this line of code is pretty self explanatory so you probably know what my next question is: Is it possible to add an equation such as

             var instantiatedProjectile : Rigidbody = Instantiate (projectile, **transform.position       +2.0**,                
             transform.rotation);"  

The question being, if I add an value, in this instance it's "transform.position + 2", shouldn't that add to the Y transform position of the instantiatedProjectile? or how exactly would I go about doing that in Javascript? And it would be nice to know how to manipulate not just the Y coordinate, but the X and Z coordinates as well. I apologize for my lack of comprehension of the script, although I am learning slowly from the tutorial what each function does, it's a lot to take in though I'll admit. Please let me know if you can, I think having the ability to change that would make the launch look "visually correct". Thanks for the help!

avatar image
0

Answer by drak0 · Aug 13, 2012 at 07:55 PM

You can't really do that, position is of type Vector3.That is why you should use the documentation ( you have the link in my first answer). Read this, all of it.So if you would want to alter Y , your code should be something like this :

 Vector3(transform.position.x, transform.position.y + N, transform.position.z) 
instead of the "transform.position + N ".But, as a better way, you could create an empty GameObject as a spawning point.Then , make the barrel of the gun a parent for the spawning point, and after that, tweak the position of the spawning point visually.Expose a variabile in the script to refer to the spawning point, so it will appear in the inspector and you just drag and drop it there.And after that, in the script, when you instantiate , you use the position of the spawning point.You will understand why the whole parent thing, if you read the link from this answer.

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 Unity_Mike2012 · Aug 14, 2012 at 12:19 AM 0
Share

Ok I got the rocket re-alignment figured out with your advice of making the spawn point an empty game object where the barrel of the launcher is, but now I've been trying to find out how to make the bullets of the machinegun play a sound when they hit something. I tried copying the audio code so that it basically looks like this

function FireOneShot () { var direction = transform.TransformDirection(Vector3.forward); var hit : RaycastHit;

// Did we hit anything? if (Physics.Raycast (transform.position, direction, hit, range)) { // Apply a force to the rigidbody we hit if (hit.rigidbody) hit.rigidbody.AddForceAtPosition(force * direction, hit.point);

// Place the particle system for spawing out of place where we hit the surface! // And spawn a couple of particles if (hitParticles) { hitParticles.transform.position = hit.point; hitParticles.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal); hitParticles.Emit();

if (audio) { if (!audio.isPlaying) audio.Play(); audio.loop = true; } } else {

Sparks.enabled = false; enabled = false;

// Play sound if (audio) { audio.loop = false; }

Of course I know this is wrong, but am I on the right track at least? I just can't figure out how to link the hitParticles to a sound. Please let me know when you get a chance, I tried looking up all the material you shared with me and I just can't seem to figure it out, because again, I don't know when to use or when not to use all of the different Javascript functions. Thanks again!

avatar image
0

Answer by drak0 · Aug 14, 2012 at 01:01 PM

Well, if the machinegun was shooting bullets as instantiated projectiles, I would check the collisions in a script attached to the projectile prefab(that being the audio source).Since it is not the case, why don't you try to just play the audio at the location of the hit? I can't say much about the performance of this way of doing things, but... you get the position of the hit where you check if you hit something. So if you hit something, play a hit sound at that location.Use this .

Also, when you copy paste code here, do it like this " <pre><code> Insert code here </code ></pre> " . This will make it readable.

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

8 People are following this question.

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

Related Questions

Mouse Focus and Gui.Window 0 Answers

Mouse move to control the animation 1 Answer

How to get mouse cursor in Vector3 1 Answer

How to convert Touch Input To Mouse Input C# unity? 0 Answers

How to interact with world space UI with a crosshair? 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