- Home /
Question by
rildofilho12c · Jun 05, 2020 at 09:26 AM ·
2dscripting problem2d-platformerscripting beginnerplatformer
How to make a companion that trails character moves, and not collide?
I got an idea of a 2D Platformer game that involves multiple characters and i want them to walk in sort of a line, and the other characters behind the primary one trails him. I could get them to follow the player with the code below, but not jump, and they don't flip the side that they're looking.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CompanionFollow : MonoBehaviour
{
public float speed;
private Transform target;
void Start ()
{
target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
}
void Update()
{
//make it move towards primary character
transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
Why does my character pass through walls when he respawns and I lose control of him? 2 Answers
How do I make it so it spawns 1 clone instead of 2? 2 Answers
2D Platform Player moving instantly from upper platform to lower, only when moving left 0 Answers
Scale object, collision not working 2 Answers
I cant get wall jumping to work in my 2D platformer (C#) 1 Answer