Rotation

Hi all,

could anyone assist please. i am trying to make the gameobject rotate as well as move to the right.

I have tried to make a separate script for the rotation, but does not work,

both scripts are below

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Projectiles : MonoBehaviour
{
[SerializeField]
[Range(0f, 5f)] float projectileSpeed = 2f;

// Start is called before the first frame update
void Start()
{
    
}

// Update is called once per frame
void Update()
{
    transform.Translate(Vector2.right * projectileSpeed * Time.deltaTime);
   
}

}

public class Spinner : MonoBehaviour
{

[SerializeField]
float speedOfSpin = 1f;
    
    
// Start is called before the first frame update
void Start()
{
    
}

// Update is called once per frame
void Update()
{
    transform.Rotate(0, 0, speedOfSpin * Time.deltaTime);
}

}

3 Likes

Hi Wesley,

What does “does not work” mean? Are there any error messages in your Console?

speed of spin is too low. You rotate 1 degree per second. Try increase number to about 800.

when i add speedOFspin to 800 this is what it does

all the axes start spinning in the same spot around the character instead of moving to the right and rotating.

rotate

well the axe moves to the right and has no spin/rotation to it.

not getting any errors.

is there a way to write this in 1 script, so that the object moves to the right and rotates?

transform.Rotate(Vector2.right * speedOfSpin * Time.deltaTime);
transform.Translate(Vector2.right * projectileSpeed * Time.deltaTime, Space.World);

I have tried this now, moves object to the right and rotates on the x axis, how can i change it so that the z axis rotates

Hi guys,

I have fixed the problem heres a way to make it move and rotate at the same time

transform.Translate(Vector2.right * projectileSpeed * Time.deltaTime, Space.World);
transform.Rotate(-Vector3.forward * speedOfSpin * Time.deltaTime);

woop woop!!! LOVE IT :slight_smile:

5 Likes

Good job, Wesley! :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms