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 $$anonymous$$ · Jun 15, 2013 at 01:05 AM · camera2dvelocitylocalspace shooter

Want Ships & Bullets to transform relative to Camera.

I'm making a 2.5D space shooter game much like R-Type and G-darius. Like G-Darius, I want the camera to fly around the level (all cinematic and stuff) with all of the on-screen action taking place relative to the camera (the plane of gameplay moves along with the camera.

If you take a look at this: http://www.youtube.com/watch?v=YUBbJu5NurE you can see that regardless of how fast the camera rotates/moves around the environment, the bullets are always relative to the camera in speed and gravity etc.

So far I make my bullets move like this (on creation in the bullet spawn object):

 var cloneLaser1 : GameObject = Instantiate(laser,shootSpwnPos1.transform.position,shootSpwnPos1.transform.rotation) as GameObject;
             cloneLaser1.rigidbody.velocity = transform.TransformDirection(Vector3.down*initialLaserSpeed);

So what I need is a local movement logic script, to tell me how I should make everything have velocity, but always being a child of the main camera so it follows it around everywhere. Any ideas? I want to avoid the parallax scrolling method and I want to make the game quite dynamic camera movement wise like you see in the video.

To clarify, it's as if the action is always static on the screen, and there's just a video playing in the background, but I don't want a video playing, I want an actual 3D environment passing the player by. I tried making bullets go along the main camera's rotation horizontal axis, but if the camera rotates, then the bullet wouldn't travel straight along the screen and veer into the background somewhere :S

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 robertbu · Jun 15, 2013 at 02:07 AM 0
Share

I'm confused here. To me, in the video all the bullets are relative to the ship, not the camera. The camera just follows the ship. Or is your setup different?

avatar image $$anonymous$$ · Jun 15, 2013 at 02:23 AM 0
Share

The camera is flying through the level, and it's as if all the assets are following it around the level. Currently my ship is the child of the camera, which means it can move around in relation to the camera axis fine. When I shoot however, if the camera is rotating around, the bullet will start going left, but then the camera rotates and the bullet starts falling further away, and will miss any enemies (it's not travelling in a straight line like in the video).

Because the world orientation of the ship is changing along with the camera's, the ship is rotating fine, I want to know how I can get a travelling bullet to do the same, so that once it's fired, it still rotates around with the camera regardless of how it's moving.

All of what I want can be achieved by just playing a movie on a plane in the background, but I want to do it properly.

avatar image robertbu · Jun 15, 2013 at 04:34 AM 0
Share

I still don't have a solid understanding of the desired behavior. One thing you can do (which surprised me the first time I did it unintentionally) is to make the projectiles a child of the camera. Just do this before setting the velocity:

 cloneLaser1.transform.parent = Camera.main.transform;

Another possibility is to give the projectiles an initial velocity that is a combination of the velocity of the camera and the velocity you want in the projectile.

avatar image $$anonymous$$ · Jun 15, 2013 at 03:29 PM 0
Share

I think robertu gave the simplest thing to try, making the projectile a child of the camera is probably the quickest way to achieve what I want. Then I can give it velocity and it will always snap to the camera's movement. Something tells me velocity will be a world thing though, and won't work locally :S so I'll have to test it out first. I'll try this first though!

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by MrThreepwood · Jun 15, 2013 at 04:20 AM

The game you're talking about pretty clearly just uses a background video. If you don't want to do that (and thus allow for an actual 3d environment for you to fly through) then you're going to need scripts that control the speed/acceleration of your projectiles. I would guess that you're currently just giving them an initial speed and letting them fly.

Instead, create a script that handles there movement, and leave their speeds/accelerations all relative to the camera. It would be easiest to simply have a specific velocity set for each projectile. As for gravity, if you want it to influence your projectiles (why?) you'll have to handle the acceleration relative to the ship as well.

Of course, I'm not sure that you can set an objects speed in a direction relative to something else, so there may be some math involved for you.

An easy way to do it, since your ship is already doing what you want it to as the camera turns, is to just take the vector of your ship.forward (assuming that your ship model is oriented properly)and set your bullets speed along the same vector. (assuming that your bullet just travels perfectly horizontal of course).

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 $$anonymous$$ · Jun 15, 2013 at 03:30 PM 0
Share

It will be travelling along the ship vector perfectly horizontally, you're correct. If you think of a pair of rails just co$$anonymous$$g out of the ship's nose, and train going back and forth on a perfectly straight line relative to the ship, regardless of how it's rotating, that's the effect I want, but ins$$anonymous$$d of the rails there, just think of them existing only in code, and the lasers will only travel one way and not come back (I make them destroy after 4 seconds anyway).

avatar image
0

Answer by $$anonymous$$ · Jun 16, 2013 at 11:19 PM

Ok guys I actually managed to work it out based on robertu's initial answer.

When I create anything (lasers, powerups, the works) I set the transform.parent to the main camera which now makes it a child of the main camera.

I then put in this code for making the lasers move on spawn, in local space relative to the parent constantly every frame in the Update() function:

 transform.localPosition = Vector3(transform.localPosition.x + (-bulletSpeed*Time.deltaTime), transform.localPosition.y, transform.localPosition.z);

This thus allows me to spawn anything, make it a child of the main camera, and then move it constantly every frame in relation to delta time, across the screen. The beauty of this of course is that I can then add another camera to do the cinematic stuff, and won't need to change parents and children etc., I can just set it as a secondary camera purely for cosmetic stuff.

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

14 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

Related Questions

Local Velocity for Rigidbody? 1 Answer

Camera.ScreenToWorldPoint with Perspective camera 1 Answer

How can I fix this screen wrapping? 1 Answer

Screen Wrap 2D Space Shooter Tut (Playmaker) 1 Answer

How to set direction of velocity using Euler angles? 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