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 /
  • Help Room /
avatar image
0
Question by DanielB89 · Oct 05, 2014 at 04:05 PM · 2dprojectilesine-wave

How to make projectile to shoot in a sine wave pattern

I'm making a 2d top down shooter like Galaga. I want the projectile to shoot from the ship and move up the screen with a sine wave pattern. This is all I got and I'm only able to move the projectile straight

 public class Projectile : MonoBehaviour {
 
     // Used to control how fast the game object moves
     public float MoveSpeed = 5.0f;
 
     // Use this for initialization
     void Start () {
         DestroyObject(gameObject, 1.0f);
 
     }
     
     // Update is called once per frame
     void Update () {
         transform.position +=
             transform.up * Time.deltaTime * MoveSpeed;
 
     }
 }
 
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
50
Best Answer

Answer by robertbu · Oct 05, 2014 at 04:26 PM

 using UnityEngine;
 using System.Collections;
 
 public class Projectile : MonoBehaviour {
     
     public float MoveSpeed = 5.0f;
 
     public float frequency = 20.0f;  // Speed of sine movement
     public float magnitude = 0.5f;   // Size of sine movement
     private Vector3 axis;
 
     private Vector3 pos;
 
     void Start () {
         pos = transform.position;
         DestroyObject(gameObject, 1.0f);
         axis = transform.right;  // May or may not be the axis you want
         
     }
     
     void Update () {
         pos += transform.up * Time.deltaTime * MoveSpeed;
         transform.position = pos + axis * Mathf.Sin (Time.time * frequency) * magnitude;
     }
 }
Comment
Add comment · Show 11 · 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 Rawlin · May 05, 2015 at 08:32 PM 0
Share

Thanks a lot :)

avatar image RealSoftGames · Jul 07, 2015 at 04:23 AM 0
Share

thanks for the temp code, i do believe this should be very similar in cos wave, thanks again for the post =)

avatar image tkamruzzaman · Sep 16, 2015 at 08:11 AM 0
Share

Nice script. Thanks a lot :)

avatar image KarlKarl2000 · Jun 24, 2016 at 06:38 PM 0
Share

Thank you!!

avatar image sdcrume · Oct 02, 2016 at 06:53 AM 0
Share

Thank you!!!

Show more comments

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

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

Related Questions

Projectiles aren't shooting the direction they're supposed to with transform.up 0 Answers

2D Projectile Script Not Working 1 Answer

Spin Projectile? 0 Answers

Rigidbody projectile misses collider 1 Answer

Problem with projectile rotation - 2D 0 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