- Home /
Question is off-topic or not relevant
Rotation problem
Hi. I have this script and....when i press play....I want each side to follow the next part. And i want to look normal. But when i press start every part rotate strange. Can someone give me a solution?
using System.Collections; using System.Collections.Generic; using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class Follow : MonoBehaviour
{
public Transform target;
public float speed = 5f;
public float rotateSpeed = 200f;
private Rigidbody2D rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate()
{
Vector2 direction = (Vector2)target.position - rb.position;
direction.Normalize();
float rotateAmount = Vector3.Cross(direction, transform.up).z;
rb.angularVelocity = -rotateAmount * rotateSpeed;
rb.velocity = transform.up * speed;
}
}
Answer by tormentoarmagedoom · Jan 24, 2019 at 04:11 PM
Good day.
Whats the problem? You are rotating them.
Are you trying to do a "snake" game? They are are doing it wrong... You are rotating each part.... you need them to move, and only rotate if the part in front is not there anymore, or something like this..
i want to every part follow and rotate like the other. A game like ,, flappy bird ''. When i tap on the screen....i want to like a snake. And i controll the head....and every part fallow the next one.
Then you need to make a script where the head knows where hi is, so can "inform" the next segment where will need to move, and the next, and the next, etc... Only the head is controled by user, the other segments will "copy" the position of the segment in front of it.
You didnt look for a solution by your own before co$$anonymous$$g here...
i just writed "unity Snake" at youtube and several tutorials appear...
https://www.youtube.com/watch?v=0$$anonymous$$x7msnqjzw&list=PLWeGoBm1YHVhc51TYY7fTLNbA02qkyLrA
Bye.
PS: Post closed.
Follow this Question
Related Questions
Instantiate a GameObject with a specific Z rotation 2 Answers
Firing Projectiles in the same direction as my character is looking. 1 Answer
How do I make my player flip to always face the enemy and vice versa? 1 Answer
How to make a 2D autoaim,How to make an autoaim for a 2D game. 0 Answers
Looking at target in 2D 1 Answer