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
1
Question by castleforce · Mar 12, 2012 at 10:17 PM · javascriptraycastingprojectilecatapult

Using Raycasting to lob a projectile.

Hey there UnityAnswer Users.

I have a Question... (Ironic?) anyway to the point.

I'm currently making a first person catapult game.

EDIT: I wish to use raycasting to cast a circle on the ground so that when a projectile is fired it will go to where the circle has been cast. The cast circle needs to be controled by using w,a,s,d. I also need to have the projectile fire with a lobbing effect (Like a catapult) when "space" is pressed.

I need to be able to select 3 different projectiles using Keys "1,2 and 3"

Any help would be much appreciated. Even hints on what to do would be great.

Thanks in advanced, Castleforce. (Trent)

EDIT: If any feed back I'm coding in Java... (Only code I know, though I'm really bad)

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
0

Answer by mpavlinsky · Mar 12, 2012 at 10:29 PM

I'm not sure I understand fully. If you are asking how to raycast you can use Physics.RayCast() and it's pretty straightforward to get the position to launch at.

If you are asking how to correctly lob the projectile you can either do some physics math to figure out the correct velocity to get your projectile to the end point with your current angle (this might be kind of difficult depending on how sharp you are with this sort of thing) or you can just kind of hack it and make a Bezier Curve that simulates what the trajectory would be and just move it along that. Bezier curves are pretty easy to implement and it's a useful thing to have access to.

Comment
Add comment · Show 10 · 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 castleforce · Mar 12, 2012 at 11:24 PM 0
Share

In a way yes, Though I want to have the raycast in a circle and controlable by the w,a,s,d or direction arrows. This way the player can position the ray cast then by pressing space the projectile will be launched from the catapult to the raycast circle... Sorry If I'm confusing.

avatar image mpavlinsky · Mar 13, 2012 at 12:45 PM 0
Share

What do you mean circle? Do you mean there is a circle on the ground where your shot is going to go?

I think you should edit your initial question to be more descriptive of the outcome you want, possibly with some sort of diagram or similar video. Also it would help to be more clear with exactly what your question is.

avatar image castleforce · Mar 14, 2012 at 06:35 AM 0
Share

Yes that is what I mean. I have edited the oringal post. I'm not sure if it takes some time to chang or not.

avatar image mpavlinsky · Mar 14, 2012 at 02:10 PM 0
Share

So basically I think what you want is to have some GameObject that sits some distance above the level and hitting the WSAD keys will move it along the X and Z planes. Whenever it gets moved you would do a raycast straight down and see where the ground is directly below it. You can figure out the rendering part here, I assume it's some combination of multitexturing, particle effect, and transparent sphere. Then you can make the Bezier Curve between that location and your catapult that you can move your projectiles along.

avatar image castleforce · Mar 15, 2012 at 03:12 AM 0
Share

Um Sorry I am physics illiterate.

Show more comments
avatar image
0

Answer by milali · Mar 12, 2012 at 10:33 PM

The simplest way to hack a curve is to add a porabola to your Y axis. so it goes up and comes down the Y while travelling along the XZ in a straight line.

this will give you a predictable lob.

if you want a physics driven approach check projectile equations in wikipedia

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

7 People are following this question.

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

Related Questions

Question about FPS and Raycasting Javascript 2 Answers

Detect face of cube clicked 4 Answers

Projectile wont move 1 Answer

Raycast script help? 1 Answer

Checking name from hit from Raycast in array 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