so i’m making a 2d game, and my player (sphere with char. controller , rigidbody and that) and 1 monster (large cube) can move just in the x axis.
so, when i jump over the cube, it rotates to follow the player, but in the process it shakes a lot, the large cube almost fall in one side, like if it were made of paper. what can i do?
also, how can i make a solid gameobject? i mean, when the player and monster collide, the player flies away and the cube falls in the ground trying to stand up, what can i do to make a realistic collide? thanks!
using UnityEngine;
using System.Collections;
public class mobAI : MonoBehaviour
{
public Transform target;
public int movespeed = 4;
public int rotationspeed = 4;
Vector3 MoveVector;
private Transform mytransform;
void Awake() //se agrega awake antes de todo, sera lo que pase primero
{
mytransform = transform;
}
void Start()
{
GameObject AI = GameObject.FindGameObjectWithTag("Player");
target = AI.transform;
}
void Update()
{
Vector3 pos = transform.position;
pos.z = 0;
transform.position = pos;
Debug.DrawLine(target.position, mytransform.position, Color.blue);
//---mirar al target---
mytransform.rotation = Quaternion.Slerp(mytransform.rotation, Quaternion.LookRotation(target.position - mytransform.position),rotationspeed * Time.deltaTime);
//toma la rotation de transform, y la gira del punto A (mytransform.rotation) al punto B (Quaternion.LookRotation), adentro del parentesis se indican los terminos
//para girar : hacia: target.position y se resta la propia rotacion actual
//*deltatime lo convierte a un movimiento en tiempo real dependiendo de los FPS de cada PC
float distance = Vector3.Distance(target.transform.position, mytransform.position);
//---mover hacia el target---
if (distance > 8.1f)
{
movespeed = 0;
}
if (distance < 8f)
{
movespeed = 4;
}
if (distance < 1.9f)
{
movespeed = 0;
}
mytransform.position += mytransform.forward * movespeed * Time.deltaTime;
}
}