4
\$\begingroup\$

I want to make a game in Unity in which the Player is a sad star. I want to have the points (The "arms and legs and head") of the star to rotate like a circle but to keep it's face (which is in it's center) still. How can I do that ?

The body should rotate and it's center should stay still. Many thanks in advance!

\$\endgroup\$

2 Answers 2

9
\$\begingroup\$

Have your gameobject hierarchy like so:

STAR
  - FACE 
  - BODY

Then rotate the Body of the star. Your face and body will be two seperate entities of course, where the face will be drawn overtop the body gameobject.

This keeps both gameobject independent from one another.

EDIT

Have your main script on the Star gameobject. Then attach the RigidBody to the Body gameobject.

Your script will rotate and move using the RigidBody component. The one caveat of this approach is that you will have to also update the "Face" gameobject to follow your RigidBody.

void LateUpdate() {
    Face.transform.position = Body.transform.position;
}
\$\endgroup\$
5
  • \$\begingroup\$ Thanks for the ideea , I'll try it , but for some reason I can't rescale the face ( I made the sprites too big in Illustrator) to enter in the body, any advice (I am a total noob , I know ).I mean , the box to rescale doesn't show up. \$\endgroup\$ Commented Aug 5, 2016 at 10:20
  • 2
    \$\begingroup\$ You can either modify the Face's Transform Scale value -- or import the sprite at a different Pixel Per Unit value. \$\endgroup\$
    – jgallant
    Commented Aug 5, 2016 at 10:30
  • \$\begingroup\$ My code is like this : using UnityEngine; using System.Collections; public class MeltoMovement : MonoBehaviour { public float speed; private Rigidbody2D rb2d; // Use this for initialization void Start () { rb2d = GetComponent<Rigidbody2D>(); } // Update is called once per frame void Update () { float moveVertical = Input.GetAxis("Vertical"); float moveHorizontal = Input.GetAxis("Horizontal"); Vector2 movement = new Vector2(moveHorizontal, moveVertical); rb2d.AddForce(movement * speed); } }. And it won't works ... \$\endgroup\$ Commented Aug 5, 2016 at 13:36
  • \$\begingroup\$ With the hierarchy , if I apply the script with Rigidbody2D to the parent(star) it also flips the face and if I apply it just to the body , even if they are both the body and the face are children of the same Star it moves only the body , while the face stays still. What am I doing wrong ? \$\endgroup\$ Commented Aug 5, 2016 at 13:38
  • \$\begingroup\$ @MihaiBarbu Updated my answer to explain the method better. \$\endgroup\$
    – jgallant
    Commented Aug 5, 2016 at 13:52
0
\$\begingroup\$

A Wheel Joint 2D should allow the face to remain relatively upright when attached to the rotating star. Think of it as the classic car model but the wheel is bigger than the car body and the car body is closer to the screen than the wheel. In this case, the wheel (star) is what has the RigidBody2D.

You might need to put a motor in the face whose speed is -1 x the star/wheel's speed.

I'm not sure you need Update code for this. Save it for if you want to change facial expressions or allow a slight rotation for some effect (speed, pain, powerups, etc.). The less code in Update, the better!

\$\endgroup\$
1
  • \$\begingroup\$ I'll keep that in mind , maybe for later updates because this is my first game and I want to keep it as simple as I can but your ideea sound awsome and after I'll finish my basic setup I'll try to use it too. Many thanks. \$\endgroup\$ Commented Aug 5, 2016 at 15:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .