- Home /
Question by
generalhak · Apr 23, 2014 at 11:11 AM ·
movementrotate
how do i rotate and movement together
hi i have a 2d sprite i want that rotate (always with variable rotatespeed) and i want that move forward (right) with variable movespeed (sprite is rigidbody and circle collider 2d ) i use this c# code but it not working well :
using UnityEngine;
using System.Collections;
public class movescript : MonoBehaviour {
/// Scrolling speed
public Vector2 speed = new Vector2(2, 2);
/// Moving direction
public Vector2 direction = new Vector2(-1, 0);
void Update()
{
// Movement
Vector3 movement = new Vector3(speed.x * direction.x,speed.y * direction.y,0);
movement *= Time.deltaTime;
transform.Rotate (0,0,10);
transform.Translate(movement);
}
}
Comment
maybe try: transform.Translate(movement, Space.World);
it would help if you explain what problem you are having with your code.
sorry my english is not good but this work ... thank you
Your answer
![](https://koobas.hobune.stream/wayback/20220613143405im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Updating rotation of client not working - strange error 0 Answers
Help with Grid Movement 2 Answers
Navigating the 3D platform 0 Answers
Rotate Character with movement 3 Answers
Calling functions in Javascript 3 Answers