Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Hogge · Jan 21, 2014 at 12:05 AM · translateparentinglocalspacelocale

Curving bullets

I've been programming for a bit over a week now. I'm working on a 2D-scrolling shooter with 3D visuals. The idea is for the game area to fly around the 3D world. Hence, everything that happens gameplay-wise should happen in coordinates relative to the GameArea prefab. I've managed to make the GameArea-prefab fly through the game world using iTween, I've managed to make the bullets parent themselves to the GameArea and I've SORT OF managed to make the bullets fire in the correct orientation. What's happening now is that the bullets behave like in the pictures below.

alt text

Also, since the problem seems so difficult to describe, I have decided to fraps it. Check out this video to better see what I mean: Link.

Below is the code for the bullet. I've decided to make it do all the parenting itself, rather than to put huge ammounts of code in the GameArea object (currently named iTweenrider in code).

 using UnityEngine;
 using System.Collections;
 
 public class Projectile : MonoBehaviour {
     public float ProjectileSpeed;
     public Transform iTweenrider;
     // Use this for initialization
     void Start () {
         
     }
     void Awake () {
         transform.parent = iTweenrider;
         //GameObject Projectile = Instantiate(Projectile,PlayerCannon ,Quaternion.identity);
         //Projectile.transform.parent = iTweenrider;
     }
     // Update is called once per frame
     void Update () {
         float amtToMove = ProjectileSpeed * Time.deltaTime;
         transform.Translate (iTweenrider.transform.forward * amtToMove);
         //transform.TransformDirection (Vector3.forward * amtToMove);
     }
 }

In case I'm not making myself clear enough, the bullets SHOULD fly towards the center of the screen, regardless of how the gamearea flies around the environment, and bullets should allways have the correct orientetion (not fly out sideways from the cannons as they do now).

scrollingshooter4.jpg (155.5 kB)
Comment
Add comment · Show 4
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 Lockstep · Jan 21, 2014 at 12:19 AM 0
Share

I'm not really sure of what you are trying to achieve. If the plane takes a turn, then it would only be natural for the bullets to keep going in their original direction. Otherwise it would look a bit awkward. Why would the bullet know that the camera turned.

If this is really what you want, then I'd suggest to move the environment ins$$anonymous$$d of every thing else.

avatar image xt-xylophone · Jan 21, 2014 at 12:48 AM 0
Share

$$anonymous$$inda looks like the bullets are children of the plane? Definitely should not be

avatar image Hogge · Jan 21, 2014 at 01:08 AM 0
Share

Well, they're children to the game area prefab. Like I said, the game is supposed to be, from a gameplay perspective, a 2D shooter. The only thing that the player can do is to turn left and right, and shoot.

But if you still think it's wrong, then please do tell me how it should, because I am a complete noob at this.

avatar image MrCrinkle · Jan 21, 2014 at 01:32 AM 0
Share

I don't think there is a problem here. The bullets are going straight, they just appear to be moving at an angle because the ship/camera is moving. I would suggest to either increase the bullet's velocity to lessen the curving effect, or add the ship's velocity to the starting velocity of the bullets.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Jan 21, 2014 at 01:41 AM

Just some points since major parts of you code are missing:

  • transform.Translate takes a direction in local space by default. You can pass Space.World to actually pass a world space direction.

  • A projectile usually should fly straighr in the direction it has been launched. So transform.Translate(Vector3.forward * amtToMove); would be the most logical way to move your projectile

  • You didn't show how you create / instantiate the bullet. Do you rotate the bullet the right way when you instantiate it?

  • You said you move the "gamearea" with iTween. What kind of movement? It looks like a sine-wave. If the whole game elements move along a sine path it will always look strange if the terrain doesn't move along.

  • It's not really clear what your gamearea actually contains and what parts are actually moving and if there are fixed parts (in relation to world space). Do you move your terrain below the aircraft or is the terrain fixed and you move the aircraft?

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 Hogge · Jan 21, 2014 at 08:52 PM 0
Share

Thanks for the input. This is the code for my cannon, which is what launches the bullet: using UnityEngine; using System.Collections;

 public class PlayerCannon : $$anonymous$$onoBehaviour {
     public GameObject ProjectilePrefab;
 
     // Use this for initialization
     //void Start () {
     
     //}
     
     // Update is called once per frame
     void Update () {
         if (Input.Get$$anonymous$$eyDown ("space")) {
             //Vector3 position = new Vector3(transform.position.x, transform.position.y +(transform.localScale.y), transform.position.z);
             Vector3 position = new Vector3(transform.position.x, transform.position.y, transform.position.z);
             Instantiate (ProjectilePrefab, position, Quaternion.identity);    
         
 
             //gameObject Projectile = Instantiate(ProjectilePrefab, position ,Quaternion.identity);
             //ProjectilePrefab.transform.parent = iTweenrider;
             
         }
     }
 }

This is where the bullet is instantiated. And yes, I guess it'll look strange, but I don't think it can be any other way if I want to have 2D shooter mechanics combined with the feeling of moving through 3D space.

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

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

Related Questions

transform.right is using Global Space rather than local 1 Answer

Move camera along 2 axes in WorldSpace 2 Answers

Animate 1 object with 5 bones? Or use translate on 5 objects? 1 Answer

Elevator that parents player to itself causes jittery motion. 1 Answer

Parenting without transform.rotation 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