Hello, I got a problem, I think it’s no about code but with Unity, but for certainty I put here code. So my problem is when I start a game, the player start move backward (fall down it look like, yes and fixed by checking kinematics but I know the kinematic can be off and it should be working) and my bullets have more force when I’m shooting downward, I don’t understand it, why it is doing this. Thanks for help.
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float walkSpeed;
private float curSpeed;
public float maxSpeed;
public float sprintSpeed;
public float speed;
public Rigidbody2D rg2d;
public Rigidbody2D bullet;
//public Transform bulletSpawn;
public float bulletSpeed;
public float xValue;
public float yValue;
//private CharacterStat plStat;
void Start()
{
//plStat = GetComponent<CharacterStat>();
//walkSpeed = (float)(plStat.Speed + (plStat.Agility/5));
walkSpeed = speed;
sprintSpeed = walkSpeed + (walkSpeed / 2);
}
void FixedUpdate()
{
curSpeed = walkSpeed;
maxSpeed = curSpeed * 2;
if (Input.GetMouseButton (0)) {
Rigidbody2D bPrefab = Instantiate(bullet, new Vector3(transform.position.x + xValue, transform.position.y + yValue, transform.position.z), Quaternion.identity) as Rigidbody2D;
bPrefab.GetComponent<Rigidbody2D>().AddForce(transform.up * bulletSpeed);
}
// Move senteces
rg2d.velocity = new Vector2(Mathf.Lerp(0, Input.GetAxis("Horizontal")* curSpeed, 0.8f),
Mathf.Lerp(0, Input.GetAxis("Vertical")* curSpeed, 0.8f));
var MousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Quaternion qot = Quaternion.LookRotation (transform.position - MousePos, Vector3.forward);
transform.rotation = qot;
}
}