I'm working on a character controller, everything works fine except two things and I can't find a way to solve this :(
This is the code of my controller script :
using UnityEngine;
public class ControlsManager : MonoBehaviour
{
public Transform playerBody;
private Rigidbody _rigidbody;
private Transform _playerCamera;
private Vector2 _mousePosition;
private Vector2 _precMousePosition;
private float _rJoystickX;
private float _rJoystickY;
private float _sprint;
private bool _jump;
private Vector3 _bodyTranslation;
private bool _bodyTranslationChange;
private Vector3 _bodyRotation;
private bool _bodyRotationChange;
private Vector3 _cameraRotation;
private bool _cameraRotationChange;
private void Awake()
{
_rigidbody = playerBody.GetComponent<Rigidbody>();
_playerCamera = Utilities.mainCamera.transform;
_mousePosition = Input.mousePosition;
}
private void Update()
{
_sprint = 1;
// Cursor lock for camera rotation
if (Input.GetKeyDown(Utilities.controls.lockCursorMouse))
{
if (Cursor.lockState == CursorLockMode.None)
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
else
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
}
if (!Utilities.isGamePaused)
{
if (Input.GetJoystickNames().Length > 0 && Input.GetJoystickNames()[0] != "")
{
// Camera rotation for controller
_rJoystickX = Input.GetAxis("RJoystickX");
_rJoystickY = Input.GetAxis("RJoystickY");
if (_rJoystickX != 0) {
_bodyRotation.y += Utilities.controls.controllerSens * _rJoystickX * Time.deltaTime;
_bodyRotationChange = true;
}
if (_rJoystickY != 0)
{
_cameraRotation.x += Utilities.controls.controllerSens * _rJoystickY * Time.deltaTime;
_cameraRotationChange = true;
}
// Movements for controller
if(Input.GetKey(Utilities.controls.sprintController))
{
_sprint = 1.6f;
}
if (Input.GetAxis("LJoystickY") > 0)
{
_bodyTranslation += playerBody.forward * _sprint * Time.deltaTime;
_bodyTranslationChange = true;
}
if (Input.GetAxis("LJoystickY") < 0)
{
_bodyTranslation -= playerBody.forward * Time.deltaTime;
_bodyTranslationChange = true;
}
if (Input.GetAxis("LJoystickX") < 0)
{
_bodyTranslation -= playerBody.right * Time.deltaTime;
_bodyTranslationChange = true;
}
if (Input.GetAxis("LJoystickX") > 0)
{
_bodyTranslation += playerBody.right * Time.deltaTime;
_bodyTranslationChange = true;
}
}
if (Cursor.lockState == CursorLockMode.Locked)
{
// Camera rotation for mouse
_precMousePosition = _mousePosition;
_mousePosition.x = Input.GetAxis("Mouse X");
_mousePosition.y = Input.GetAxis("Mouse Y");
if (_mousePosition.x != _precMousePosition.x)
{
_bodyRotation.y += _mousePosition.x * Utilities.controls.mouseSens;
_bodyRotationChange = true;
}
if (_mousePosition.y != _precMousePosition.y)
{
_cameraRotation.x += -_mousePosition.y * Utilities.controls.mouseSens;
_cameraRotationChange = true;
}
// Movements for mouse
_sprint = 1;
if(Input.GetKey(KeyCode.LeftShift))
{
_sprint = 1.6f;
}
if (Input.GetKeyDown(KeyCode.Space))
{
_jump = true;
}
if (Input.GetKey(Utilities.controls.forward))
{
_bodyTranslation += playerBody.forward * (_sprint * Time.deltaTime);
_bodyTranslationChange = true;
}
if (Input.GetKey(Utilities.controls.backward))
{
_bodyTranslation -= playerBody.forward * Time.deltaTime;
_bodyTranslationChange = true;
}
if (Input.GetKey(Utilities.controls.left))
{
_bodyTranslation -= playerBody.right * Time.deltaTime;
_bodyTranslationChange = true;
}
if (Input.GetKey(Utilities.controls.right))
{
_bodyTranslation += playerBody.right * Time.deltaTime;
_bodyTranslationChange = true;
}
///////////////////////////////// Debug
if (Input.GetKey(KeyCode.DownArrow))
{
_bodyTranslation -= playerBody.up * Time.deltaTime;
_bodyTranslationChange = true;
}
if (Input.GetKey(KeyCode.UpArrow))
{
_bodyTranslation += playerBody.up * Time.deltaTime;
_bodyTranslationChange = true;
}
}
}
// Rotations
if (_bodyRotationChange)
{
playerBody.localRotation *= Quaternion.Euler(_bodyRotation);
}
_bodyRotationChange = false;
_bodyRotation = Vector3.zero;
if (_cameraRotationChange)
{
_playerCamera.localRotation *= Quaternion.Euler(_cameraRotation);
}
_cameraRotationChange = false;
_cameraRotation = Vector3.zero;
if (Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
}
}
private void FixedUpdate()
{
if (_bodyTranslationChange)
{
_rigidbody.AddForce(_bodyTranslation * Utilities.controls.playerSpeed, ForceMode.VelocityChange);
}
if (_jump)
{
_jump = false;
_rigidbody.AddForce(playerBody.up * 500, ForceMode.Impulse);
}
_rigidbody.drag = playerBody.position.y > -0.6f ? 1 : 8;
_bodyTranslationChange = false;
_bodyTranslation = Vector3.zero;
}
}
The main two problems are :
As I do rotations in Update, and movements in FixedUpdates, there is some annoying jitter when I both move and rotate at the same time. I tried to show this in a gif but everything seems laggy so I can't really show it.
As I use AddForce() to move my character, I had to increase the drag of my rigidbody (up to 8) si it doesn't "slide" when you stop moving. This works great but now I can't jump properly because of that. I found a workaround, by putting the drag back to 1 when I'm in the air, but then if I jump and move, I move 8x faster in the air which is annoying aswell.
Am I doing thinks completely wrong ? I first did not use AddForce but normal vector translations to move the character, but collisions were buggy as hell, I could go through most walls, objects... etc
Thanks if you read all that !
when working with Pyhsics (RB) NEVER change the transform directly and never ever to this in Update! all changes have to be made inside FixedUpdate!
playerBody.localRotation *= Quaternion.Euler(_bodyRotation); <-- in Update.
Also use Rigidbody.MoveRotation instead of directy change values.
This happens because of pyhsics will work in a different update process and when you change Values within this process unity gets confused and you break the physics -> Jitter
Ok, after hours of trying to make something smooth with Rigidbody, I can't get anything perfect.
I'll just use a basic Character controller and handle collisions myself.
Thanks anyway !
Related
here's my jump code it updates in void Update
void Jump()
{
if(isgrounded == true)
{
amountofjumps = jumps;
}
if(Input.GetKeyDown(KeyCode.UpArrow) && amountofjumps > 0)
{
rb2d.velocity = Vector2.up * jump * Time.deltaTime;
amountofjumps--;
}
else if(Input.GetKeyDown(KeyCode.UpArrow) && amountofjumps == 0 && isgrounded == true)
{
rb2d.velocity = Vector2.up * jump * Time.deltaTime;
}
}
here are the variables I use for my jump code
bool isgrounded;
public float groundcheckradius;
public LayerMask whatisground;
public float jump;
private int amountofjumps;
public int jumps;
here's how I detect the ground
void checkforground()
{
isgrounded = Physics2D.Raycast(transform.position,Vector2.down, groundcheckradius,whatisground);
}
void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawLine(transform.position, transform.position + Vector3.down * groundcheckradius);
}
thanks in advance
Velocity is often used for moving object try rigidbody2d.AddForce() instead.
void Jump()
{
if (isgrounded == true)
{
amountofjumps = jumps;
}
if (Input.GetKeyDown(KeyCode.UpArrow) && amountofjumps > 0 && isgrounded == true)
{
rb2d.AddForce(transform.up * jump, ForceMode2D.Impulse);
amountofjumps--;
}
}
First of all Time.deltaTime makes no sense when setting a velocity. A velocity already is frame-rate independent so when you multiply a velocity by Time.deltaTime (about 0.017 for 60 fps) it becomes extremely small/slow.
Secondly currently you overwrite the entire velocity so if your player is moving forward it will completely stop any movement on the X axis.
And finally when you are grounded you want always be able to jump ... not only if amountofjumps == 0 which will never be the case since right before you have set it to amountofjumps = jumps;! You don't want to check the amountofjumps at all when jumping from the ground!
You would probably rather use e.g.
// get the current velocoty of the rigidbody
var velocity = rb2d.velocity;
// Only overwrite the Y velocity with the jump
velocity.y = jump;
// re-assign the changed vector to the rgidbody
rb2d.velocity = velocity;
And then I would change the logic to something like e.g.
private void Jump()
{
if(isgrounded)
{
amountofjumps = jumps;
// when you are grounded you can always jump!
// Not only when the amountofjumps == 0
// actually when you are grounded the amountofjumps shouldn't matter at all
if(Input.GetKeyDown(KeyCode.UpArrow))
{
DoJump();
}
}
// As before while not grounded the amountofjumps is taken into account
else if(amountofjumps > 0)
{
if(Input.GetKeyDown(KeyCode.UpArrow))
{
DoJump();
}
}
}
private void DoJump()
{
// get the current velocoty of the rigidbody
var velocity = rb2d.velocity;
// Only overwrite the Y velocity with the jump
velocity.y = jump;
// re-assign the changed vector to the rgidbody
rb2d.velocity = velocity;
// Always reduce the amount of jumps also when jumping from the ground
amountofjumps--;
}
we have a dash button in the game. If we press the button dash button is working well but the problem is if we press anywhere on screen it is working too! We only want to work that function with button.
Anyone help us please?
Code:
public void Dash()
{
if (Input.GetMouseButtonDown(0))
{
activeMoveSpeed = dashSpeed;
dashCounter = dashLength;
}
if (dashCounter > 0)
{
canShoot = false;
dashCounter -= Time.deltaTime;
if (dashCounter <= 0)
{
canShoot = false;
activeMoveSpeed = speed;
dashCoolCounter = dashCoolDown;
}
}
if (dashCoolCounter > 0)
{
canShoot = false;
dashCoolCounter -= Time.deltaTime;
}
}
private void FixedUpdate()
{
Movement();
Dash();
}
Button and Game
Button
The function you specify in OnClick will be called whenever the button is clicked.
Currently, you are not using the button at all. I think you meant something like this (StartDash() is the function that should be chosen in OnClick):
public void StartDash()
{
activeMoveSpeed = dashSpeed;
dashCounter = dashLength;
}
private void DoDash()
{
if (dashCounter > 0)
{
canShoot = false;
dashCounter -= Time.deltaTime;
if (dashCounter <= 0)
{
canShoot = false;
activeMoveSpeed = speed;
dashCoolCounter = dashCoolDown;
}
}
if (dashCoolCounter > 0)
{
canShoot = false;
dashCoolCounter -= Time.deltaTime;
}
}
private void FixedUpdate()
{
Movement();
DoDash();
}
Take a look at the related pages in the Unity Documentation:
Manual - Button
Scripting - UI.Button
Scripting - UI.Button.onclick
I made an animation where if you click one of the logos, the one that got clicked will move towards the center and the other logos will move to the sidewards enter image description here, but somehow the code that I developed only works on the blue logo (Designer). The engineer(Green) and artist(Yellow) doesn't not work when I click them.
Even after the animation is finished, the other logo still did not respond.
void Update()
{
if (Input.GetMouseButtonDown(0))
{
onCenter = true;
}
Movement();
}
// Functions//
private void OnMouseDown()
{
Vector3 mousePos;
mousePos = Input.mousePosition;
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
}
private void Movement()
{
if (onCenter)
{
this.gameObject.transform.position = Vector3.MoveTowards(this.gameObject.transform.position, center, speed * Time.deltaTime);
if (this.gameObject.tag == "Artist")
{
Engineer.gameObject.transform.localPosition = Vector3.MoveTowards(Engineer.gameObject.transform.localPosition, Estandby, speed * Time.deltaTime);
Designer.gameObject.transform.localPosition = Vector3.MoveTowards(Designer.gameObject.transform.localPosition, Dstandby, speed * Time.deltaTime);
}
else if (this.gameObject.tag == "Designer")
{
Engineer.gameObject.transform.localPosition = Vector3.MoveTowards(Engineer.gameObject.transform.localPosition, Estandby, speed * Time.deltaTime);
Artist.gameObject.transform.localPosition = Vector3.MoveTowards(Artist.gameObject.transform.localPosition, Astandby, speed * Time.deltaTime);
}
else if (this.gameObject.tag == "Engineer")
{
Designer.gameObject.transform.localPosition = Vector3.MoveTowards(Designer.gameObject.transform.localPosition, Dstandby, speed * Time.deltaTime);
Artist.gameObject.transform.localPosition = Vector3.MoveTowards(Artist.gameObject.transform.localPosition, Astandby, speed * Time.deltaTime);
}
if(Engineer.gameObject.transform.position.x== 8.251f|| Designer.gameObject.transform.position.x == 8.251f|| Artist.gameObject.transform.position.x == 8.251f)
{
onCenter = false;
}
}
}
Please advice
I bet you forgot to add (attach) the script to the other logos ;)
Player controller constantly rotates the player when there is no input. The player is idle, not rotating, until the up arrow is pressed. Then it begins rotating constantly.
This happens whether mouseRotate is true or not.
If tried a number of things, including commenting out the mouserotate line altogether, as well as taking out the animations temporarily.
using UnityEngine;
//using UnityStandardAssets.CrossPlatformInput;
using UnityEngine.Networking;
public class PlayerController : MonoBehaviour
{
// Updated 2019-11-06 //
public float movementSpeed=1;
public float runSpeed=2;
bool isOnGround;
Rigidbody rb;
private Vector3 moveDirection = Vector3.zero;
private Animator anim;
public bool mouseRotate = true;
public float rotationSpeed = 200f;
void Start()
{
rb = GetComponent<Rigidbody>();
anim = GetComponent<Animator>();
}
void Update()
{
updateAnim();
ProcessJumping();
moveDirection.y -= 10f * Time.deltaTime;
if (mouseRotate)
{
transform.Rotate(Vector3.up * (Input.GetAxis("Mouse X")) * Mathf.Sign(Input.GetAxis("Horizontal")), Space.World);//mouse rotate
if (Input.GetKey("up") || Input.GetKey("down"))
{
transform.Translate(0, 0, Input.GetAxis("Vertical") * Time.deltaTime * movementSpeed);
}
if (Input.GetKey("left") || Input.GetKey("right"))
{
transform.Translate(Input.GetAxis("Horizontal") * Time.deltaTime * runSpeed, 0, 0);
}
}
else//traditional keyboard controls-- can implement menu to choose rotation style
{
// updated by Yizhi 11/10/2019
if (Input.GetKey("up") || Input.GetKey("down"))
{
transform.Translate(0, 0, Input.GetAxis("Vertical") * Time.deltaTime * movementSpeed);
}
if (Input.GetKey("right") || Input.GetKey("left"))
{
transform.Rotate(0, Input.GetAxis("Horizontal") * Time.deltaTime * rotationSpeed, 0);
}
}
}
void ProcessJumping()
{
CheckIfOnGround();
if (Input.GetKeyDown(KeyCode.Space) && isOnGround)//(Input.GetKeyDown(KeyCode.Space) && isOnGround)//removed until network control implememnted
{
transform.Translate(0, 0.75f, 0);
isOnGround = false;
anim.SetBool("Jump_b", true);
}
}
void CheckIfOnGround() {
Ray[] rays = new Ray[3];
rays[0] = new Ray(transform.position - Vector3.right * .45f, Vector3.down);
rays[1] = new Ray(transform.position, Vector3.down);
rays[2] = new Ray(transform.position + Vector3.right * .45f, Vector3.down);
RaycastHit hit;
float maxD = .1f;
foreach (Ray ray in rays)
{
if (Physics.Raycast(ray, out hit, maxD))
{
if (hit.collider != null)
{
isOnGround = true;
}
else
{
isOnGround = false;
}
}
}
}
void updateAnim()
{
if ( (Input.GetKey(KeyCode.UpArrow) && Input.GetKey(KeyCode.RightShift)))//(Input.GetKey(KeyCode.UpArrow) && Input.GetKey(KeyCode.LeftShift) ||//temporarily removed until network controls are added. Left keyboard belongs to julie, right keyboard belongs to dot
{
// Updated 2019-11-06 //
anim.SetFloat("Speed_f", runSpeed);
}
else if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.DownArrow))
{
// Updated 2019-11-06 //
anim.SetFloat("Speed_f", movementSpeed);
}
else
{
//ELSE idle
anim.SetFloat("Speed_f", 0);
}
}
}
You setup your rigidbody to not rotate your object by locking those rotational axis on the rigidbody component, then if you do need to rotate your player you can manually do it through code. This has been the approach I have successfully used in the past. :)
I've written the following code making the gun move to the guy's shoulder position when he stops shooting and it does work...BUT ONLY ONCE. After that, it starts not to meet the target even though it's coordinates remain the same. I've tried it with Lerp, SmoothDamp, MoveTowards...still don't get where the problem lies.
P.S. The gun moves to the shoulder when shooting perfectly, it starts happening when the character stops shooting and tries to go back to the Idle pose.
EDIT: Turns out there's also something wrong with rotation...or maybe it's just rotation. I don't even know at this point.
THE VIDEO of what's going on: https://youtu.be/CheQiomYtm8
THE CODE:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnitControl;
public class BlastIKController : MonoBehaviour
{
public WeaponState wpState;
public GameObject weapon;
public GameObject RightShoulder;
public GameObject HumanSpine;
public GameObject WeaponSpawn;
public LayerMask lmask;
public BlastIKHandler ikHandle;
public Material targetMat;
public Material defMat;
public GameObject target;
public GameObject WeaponIdle;
public bool isShooting = false;
//public bool InIdle = true;
LineRenderer ShootLine;
public GameObject WeaponInstance;
Animator anim;
public float speedMove;
public float speedRot;
// Use this for initialization
void Awake()
{
GameObject weaponInst = Instantiate(weapon, WeaponSpawn.transform);
WeaponInstance = weaponInst;
WeaponInstance.transform.localPosition = new Vector3(0, 0, 0);
wpState = weaponInst.GetComponent<WeaponState>();
ikHandle = this.GetComponent<BlastIKHandler>();
ShootLine = this.GetComponent<LineRenderer>();
anim = this.GetComponent<Animator>();
ikHandle.RightShoulder = RightShoulder;
ikHandle.leftHandTarget = wpState.leftHandIdle.transform;
ikHandle.rightHandTarget = wpState.rightHandTarget.transform;
//Позиция оружия
wpState.shoulder.transform.position = ikHandle.WeaponIdlePos.position;
wpState.shoulder.transform.rotation = ikHandle.WeaponIdlePos.rotation;
}
// Update is called once per frame
void Update()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
#region SearchTarget
if (Physics.Raycast(ray, out hit, Mathf.Infinity, lmask))
{
if (hit.collider.gameObject.tag == "Target")
{
ShootLine.positionCount = 2;
ShootLine.SetPosition(0, HumanSpine.transform.position);
ShootLine.SetPosition(1, hit.collider.gameObject.transform.position);
if (Input.GetMouseButton(0))
{
if (target == null)
{
target = hit.collider.gameObject;
MeshRenderer ms = hit.collider.gameObject.GetComponent<MeshRenderer>();
ms.material = targetMat;
ikHandle.targetPos = hit.collider.gameObject;
}
else
{
MeshRenderer ms = target.GetComponent<MeshRenderer>();
ms.material = defMat;
target = hit.collider.gameObject;
ms = target.GetComponent<MeshRenderer>();
ms.material = targetMat;
ikHandle.targetPos = hit.collider.gameObject;
}
}
}
}
#endregion
#region Shooting
Shooting();
if (isShooting)
{
if (target != null)
{
bool isShoot = anim.GetBool("Shoot");
if (!isShoot)
{
StartCoroutine(MoveToShoot(RightShoulder.transform.position));
ikHandle.leftHandTarget = wpState.leftHandTarget.transform;
anim.SetBool("Shoot", true);
//InIdle = false;
}
}
}
else
{
// float stepMove = speedMove * Time.deltaTime;
// wpState.shoulder.transform.position = Vector3.Lerp(wpState.shoulder.transform.position, ikHandle.WeaponIdlePos.position, stepMove);
// //if (!InIdle)
// //{
// // StartCoroutine(MoveToIdle(ikHandle.WeaponIdlePos.position));
//// }
// //InIdle = true;
// //float stepMove = speedMove * Time.deltaTime;
// //while (wpState.shoulder.transform.position != ikHandle.WeaponIdlePos.position)
// //{
// // wpState.shoulder.transform.position = Vector3.Lerp(wpState.shoulder.transform.position, ikHandle.WeaponIdlePos.position, stepMove);
// //}
// ////wpState.shoulder.transform.position = ikHandle.WeaponIdlePos.position;
// ////wpState.shoulder.transform.position = Vector3.MoveTowards(wpState.shoulder.transform.position, ikHandle.WeaponIdlePos.position, stepMove);
// float stepRot = speedRot * Time.deltaTime;
// //while (wpState.shoulder.transform.rotation != ikHandle.WeaponIdlePos.rotation)
// //{
// wpState.shoulder.transform.rotation = Quaternion.Slerp(wpState.shoulder.transform.rotation, ikHandle.WeaponIdlePos.rotation, stepRot);
// //}
// ////wpState.shoulder.transform.rotation = ikHandle.WeaponIdlePos.rotation;
// ikHandle.leftHandTarget = wpState.leftHandIdle.transform;
// anim.SetBool("Shoot", false);
}
#endregion
}
void LateUpdate()
{
if (!isShooting)
{
float stepMove = speedMove * Time.deltaTime;
stepMove += Time.deltaTime / speedMove;
Vector3 velocity = Vector3.zero;
//.shoulder.transform.position = Vector3.Lerp(wpState.shoulder.transform.position, ikHandle.WeaponIdlePos.position, stepMove);
wpState.shoulder.transform.position = Vector3.MoveTowards(wpState.shoulder.transform.position, ikHandle.WeaponIdlePos.position, stepMove);
//wpState.shoulder.transform.position = Vector3.SmoothDamp(wpState.shoulder.transform.position, ikHandle.WeaponIdlePos.position, ref velocity, stepMove);
// wpState.shoulder.transform.position = Vector3.SmoothDamp()
float stepRot = speedRot * Time.deltaTime;
wpState.shoulder.transform.rotation = Quaternion.Slerp(wpState.shoulder.transform.rotation, ikHandle.WeaponIdlePos.rotation, stepRot);
ikHandle.leftHandTarget = wpState.leftHandIdle.transform;
anim.SetBool("Shoot", false);
}
}
void Shooting()
{
if (Input.GetKeyDown(KeyCode.S))
{
isShooting = !isShooting;
}
}
IEnumerator MoveToShoot(Vector3 WPposition)
{
float step = speedMove * Time.deltaTime;
while (wpState.shoulder.transform.position != WPposition)
{
wpState.shoulder.transform.position = Vector3.Lerp(wpState.shoulder.transform.position, WPposition, step);
Vector3 relativeWeaponPos = ikHandle.targetPos.transform.position - wpState.shoulder.transform.position;
Quaternion WeaponRotation = Quaternion.LookRotation(relativeWeaponPos);
wpState.shoulder.transform.rotation = Quaternion.Slerp(wpState.shoulder.transform.rotation, WeaponRotation, step);
yield return null;
}
}
IEnumerator MoveToIdle(Vector3 WPposition)
{
float stepMove = speedMove * Time.deltaTime;
float stepRot = speedRot * Time.deltaTime;
while (wpState.shoulder.transform.position != WPposition)
{
wpState.shoulder.transform.position = Vector3.Lerp(wpState.shoulder.transform.position, WPposition, stepMove);
wpState.shoulder.transform.rotation = Quaternion.Slerp(wpState.shoulder.transform.rotation, ikHandle.WeaponIdlePos.transform.rotation, stepRot);
yield return null;
}
wpState.shoulder.transform.position = Vector3.Lerp(wpState.shoulder.transform.position, ikHandle.WeaponIdlePos.position, stepMove);
}
}
So, it was the following. It turns out that the coroutines got mixed up in Update and they worked at the same time.
So...I removed all coroutines from the code and then moved and rotated using Lerp and sLerp in the update.
There's one thing though, I also had to add a check for both bositions to meet, and after that it starts shooting and only then.
P.S. I can add the code I changed later if you like.