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 SmorgonMagma · Mar 15, 2012 at 06:16 AM · turretlasertranslation

Can't get my laser beam to rotate

I've created a laser turret with a spawn point at the end of the gun. To fire the laser, I'm spawning a cube at the spawn point and scaling the cube to the length that I need for the laser. The problem is that the laser shows up facing the correct direction but half of it is in front and half at the back of the turret. I know that this is because of the origin point of the cube being dead centre of the cube. What I'm trying to do is shift the laser in the facing direction of the turret half of the length of the laser beam. I've tied everything I can think of and I can't get this part to work. One solution is to create an object with it's axes at one side then the scaling will take care of things. I I'm still curious to know if there's a simple Unity solution to this.

Any ideas?

Comment
Add comment · Show 1
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 syclamoth · Mar 15, 2012 at 06:17 AM 0
Share

Non-uniform scaling is liable to cause problems in any case. Have you tried using a LineRenderer for this? They seem like the obvious choice for lasers...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SmorgonMagma · Mar 15, 2012 at 01:15 PM

Actually, I solved this just after I posed the question. For anyone that's interested in how I did it, here's the code for the turret (which aligns itself with the player then scales the laser (a standard cube of 1x1x1 to the distance from the player then shifts itself along the local z axis of the attached spawn point by half the distance. The transform.Translate at the bottom of the code was the fix for my problem.

function Update() {

var amtToMove = LaserSpeedX * Time.deltaTime;

var relativePoint = transform.InverseTransformPoint(Player.position);

if(relativePoint.x <= -1.0) transform.Translate(Vector3.left amtToMove); else if(relativePoint.x >= 1.0) transform.Translate(Vector3.right amtToMove);

// Fire the laser if aligned else if(!LaserReloadTimer) { if(relativePoint.z < 50) {
// Create the laser var tempLaser = Instantiate(LaserShotZ,LaserSpawnPt.position,LaserSpawnPt.rotation);

   // Set the length to the distance of the player
   tempLaser.transform.localScale.z = relativePoint.z;

   // Reposition relative to the laser centre point
   tempLaser.transform.Translate(Vector3(0,0,1)*relativePoint.z/2);
   LaserReloadTimer = LaserReloadTime;

}

} else LaserReloadTimer--; }

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Help moving turret shoot lasers 2 Answers

Vector3.Forward not working? 1 Answer

I'm a coding noob. For the life of me I'm not able to figure out why the while loop is going infinitely? Any and all help is appreciated. Here is the code. 1 Answer

Why does this script work correctly? 1 Answer

transform.Translate() going nuts with Z/X axes? 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