• 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 whoshotdk · Sep 23, 2020 at 05:04 PM · transform.translatetransform.rotate

Simple parent/child transform - child not following rotation

I'm building a top down snake game (3D view).

'Snake head' is an empty transform with several mesh gameobjects under it to make up the visual for the snake's head.

'Snake head' has a script on it;

 public class SnekController : MonoBehaviour {
 
     public float translateSpeed;
     public float rotateSpeed;
 
     private void Update() {
 
         // Translation...
 
         this.transform.Translate(this.transform.forward * this.translateSpeed * Time.deltaTime);
 
         // Rotation...
 
         if (!Input.GetMouseButton(0))
             return;
 
         float halfWidth = Screen.width / 2;
         this.Turn(Input.mousePosition.x < halfWidth ? -1 : 1);
     }
 
     private void Turn(int _direction) {
 
         this.transform.Rotate(0, this.rotateSpeed * _direction * Time.deltaTime, 0);
     }
 }

The snake turns left or right depending on if the mouse was pressed on the left or right side of the screen. It seemed to work, when the head just had a non-descript sphere under it.

Now that I've added a tongue and some eyes (children of the 'snake head') - they themselves are NOT rotating along with the parent ... OR rather ... although I'm telling the 'snake head' to translate along it's forward axis, I've noticed that as I turn it seems to not do that; for example if I turn 90 degrees the head will now be moving along it's X axis.

I gotta be doing something really stupid, but I just cannot see it.

There is no other code anywhere else, just the controller I've posted.

Thanks for looking!

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
0
Best Answer

Answer by whoshotdk · Sep 23, 2020 at 05:16 PM

It's always the same, you spend 20 minutes writing out the problem and then 2 minutes later you discover the solution yourself.

Turns out 'transform.Translate' works in local-space by default. Adding 'Space.World' as the last parameter seems to have sorted everything out.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

208 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 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 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 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 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 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 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 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 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 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

Duplicate, Translate and Rotate Quad so that edges meet 0 Answers

Sprite moves at an angle that is 2x the rotation of the sprite. 1 Answer

How to Rotate and move a character like in WOW 0 Answers

Programming knife swing 1 Answer

How to ignore rotation while moving? 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges