Please help me with a script for an sprite follow another sprite, i searched on google and i found a lot of scripts, but the sprite that is supposed to follow isn’t moving.
ok let me tell you about my project, i have two sprites.
Sprite A and Sprite B. Sprite A is the Player and Sprite B is the Enemy
i have a controller on sprite A with some inputs, “W” for up, “S” for down, and the sprite is moving forward continuous.
i want that sprite B following sprite A on X axis, and if the players hits up or down, the sprite B should follow the exact path of the Sprite A
let’s say there is an obstacle and Sprite A goes up and then down, Sprite B will follow the exact path.
this is the controller for sprite A:
using UnityEngine;
using System.Collections;
public class Miscare : MonoBehaviour {
public Sprite playerSprite;
public float speed = 1f;
public float moveForce = 2.0f;
private Vector3 moveDirection = Vector3.zero;
public float forwardMovementSpeed = 3.0f;
private float NewSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.W))
transform.position += new Vector3 (0.0f, speed * Time.deltaTime, 0.0f);
if (Input.GetKey (KeyCode.S))
transform.position -= new Vector3 (0.0f, speed * Time.deltaTime, 0.0f);
//Feed moveDirection with input.
moveDirection = new Vector3(Input.GetAxis(“Horizontal”), 0, Input.GetAxis(“Vertical”));
moveDirection = transform.TransformDirection(moveDirection);
//Multiply it by speed.
moveDirection = speed;
//Making the character move
transform.Translate(Vector3.forward * Input.GetAxis(“Vertical”) * Time.deltaTimespeed);
Vector2 newVelocity = rigidbody.velocity;
newVelocity.x = NewSpeed;
rigidbody.velocity = newVelocity;
NewSpeed = forwardMovementSpeed + speed;
}
}
Sorry for my bad English. if you want to now more please ask me.
Thank you,
Andrei