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 DevMerlin · Oct 28, 2012 at 11:44 PM · physicsside-scrollingarcthrowing

Throw a weapon in a physics arc with a lead to a target?

I am building a side-scrolling game and trying to throw grenades at characters on the screen at the same time, with the point of origin being the camera. While I've gotten the arc to work, it still needs a lead time in order to actually be visible on the screen. Can anyone suggest a method of doing a light arc with a lead to hit a target, using either physics or transform? I'm willing to switch if there's a better method.

Comment
Add comment · Show 3
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 Fattie · Oct 29, 2012 at 07:58 AM 0
Share

question, is your "hero" (whatever throws the grenade) and your "enemy" always moving at the same speed in your game?

secondly TBC this is a 2D game right? when you say it's thrown "from the camera" that sounds a bit strange - do you mean from the plane of action, basically from the middle of what will be the screen?

avatar image Fattie · Oct 29, 2012 at 08:02 AM 0
Share

for the record it would be a parabola I guess. "arc" often means a segment of a circle.

avatar image DevMerlin · Oct 29, 2012 at 03:53 PM 0
Share

No, the target can vary it's speed up until the first time it's hit with an explosive radius. However, the camera is following at roughly the same speed - the target varies just enough to be slightly harder to hit. Yes, this is a 2D game, and the weapon is being thrown from essentially the middle of the screen to make it look like the player is throwing it. Once the target is in the air it's speed depends on the blast power. I guess parabola is also correct ^^;

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Montraydavis · Oct 29, 2012 at 12:19 AM

This is sort of an answer since it gets the job done, but, I too am wanting to know more about this topic. I have some basic scripting that instantiates, levels at a height of x, and shoots toward the enemy until hit, then explodes and dies.

 //Shuriken.js
 
 var Target : GameObject ;
 var TargetDistance : float ;
 var ShurikenSpeed : float = 50 ;
 var Life : float = 3 ;
 
 function Start () {
     Target = GameObject.Find ( "Troll" ) ;// Assign Target To ZTarget
 }
 
 function Update () {
     Life -= 1 * Time.deltaTime ;
     
     if ( Mathf.Ceil ( Life ) == 0 )
     {
         Instantiate( Resources.Load ( "Detonator-Crazysparks" ), transform.position, Quaternion.identity ) ;
         GameObject.Destroy ( gameObject ) ;
     }
     
     if ( Mathf.Ceil ( TargetDistance ) == 2 ){
         ShurikenSpeed = 10 ;
     }
     transform.rotation.y = 90 ;s
     transform.position += transform.forward * ShurikenSpeed * Time.deltaTime; // Move Entity Toward Target
     //transform.rotation = Quaternion.Slerp ( transform.rotation, Quaternion.LookRotation ( - ( transform.position - Vector3(Target.transform.position.x , Target.transform.position.y+0.1, Target.transform.position.z) ) ), 1 * Time.deltaTime ) ;
     transform.LookAt ( Target.transform ) ;
     transform.position.y = 1;    
 }
 
 function OnTriggerEnter ( collision : Collider )
 {
     if ( collision.tag == "Zombie" ){
         
         Instantiate( Resources.Load ( "Detonator-Crazysparks" ), transform.position, Quaternion.identity ) ;
         GameObject.Destroy ( gameObject ) ;
     
     }
 }


 //NinjaController
 
 function Update ( ) {
     if ( Input.GetKeyDown ( KeyCode.S ) && animator.GetFloat ( "CoolDown" ) < 0.1 )
         {
         
         Instantiate( Resources.Load ( "Shuriken" ), Vector3 ( transform.position.x, 1, transform.position.z), Quaternion.identity) ;
         
             
     }
 }

Anyone have a better method than this, would be greatly appreciated to post ! :D

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 DevMerlin · Oct 29, 2012 at 12:52 AM 0
Share

I think I may go with Transform ins$$anonymous$$d of Physics-based. Hoping it'll help keep the weapons on-screen as things move after they're fired.

avatar image Montraydavis · Oct 29, 2012 at 02:20 AM 0
Share

The script above has no physics involvement, and is based solely off of transform. Thumbs up if this has helped.

avatar image DevMerlin · Oct 29, 2012 at 02:29 AM 0
Share

No luck.. I tried it and still didn't get the thing working. I'm using the code from this as my base, but I need to add a lead time to the projectile when it's in the arc so it doesn't go off screen: http://answers.unity3d.com/questions/145972/how-to-make-enemy-canon-ball-fall-on-mooving-targe.html

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

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 1 Answer

2D 360 degress platformer example needed 0 Answers

Calculate a trajectory in all possible directions (2D). 2 Answers

How do I arc a rigidbody so it lands on a target? 2 Answers

Spear throwing with HTC Vive 3 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