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 MMCDeveloper · Aug 12, 2014 at 09:43 PM · local axisstrafe

Move objects in a scene based on the main characters local X axis?

Having a hell of time trying to sort this business out. I have a space shooter that lets the ship rotate using transform.rotation = Quaternion.Euler(Vector3(0, angle, 0)); to constantly look at the mouse. The ship itself doesn't move, but the rest of the environment moves around it. At this stage I need to create a strafe, and to the best of my knowledge the only logical way to do that is to have all of the objects which do move in the scene to move on the space ships local x axis. How do I move an Object based on another unrelated objects local x axis? The attempts that I've been working with so far include using a child of the ship itself to create an offset from Vector3(0,0,0) that applies to (1,0,0) at the start of the game. This would likely work in creating my offset, but for some reason when the ship rotates the offset never changes. Essentially when the ship rotates 90 degrees on the Y axis, and now the child object sits at (0,0,1) the input to my code still shows the object (strafeleft) to have a position of (1,0,0). It's killing me. I've tried both transform.position, and transform.localPosition so far no change. Strafeleft is declared as a transform.

 if(Input.GetButton("a"))
         {
             mark = 0;
             speed = (movespeed/100) * distance;
                         movedirection = strafeleft.position;
                         movedirection.x = transform.position.x + movedirectionb.x;
             movedirection.z = transform.position.z + movedirectionb.y;
             movedirection.y = -12;
             transform.position = Vector3.MoveTowards(transform.position, movedirection, speed*Time.deltaTime);
             timerdrift = speed;
             speed1 = speed;            
         }
 


 


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 robertbu · Aug 12, 2014 at 09:46 PM 0
Share

For all the object's in the scene (assu$$anonymous$$g the character remains level on the XZ plane), you want to add the character's transform.right times some value to move left/right relative to the character. I don't know how you have your game setup, but something like:

 transform.position = character.transform.right * speed * Time.deltaTime * direction;

Where direction will be either -1 or 1 depending on which direction you are strafing.

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Unity 5 character movement problem with strafing left and right,Cannot get rid of left and right strafing. Help Please! 0 Answers

Xbox 360 controller values 1 Answer

Is it possible to create a third Axis? 1 Answer

Get the position behind an object (locally) ? 1 Answer

How to make the character strafe while running? 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