Hi, I’m new to unity, and I am trying to create a simple game where a cube moves and jump around a field.
I encountered a problem, sometimes, when the cube jumps and moves he flips and he falls facing the ground with another face than the starting one, this creates a problem when I use the AddForce to move.
I tried to use a Father Gameobject, but, since the father can’t have a collider I can’t use the method AddForce (I must use transform.translate) and every time the cube hits a wall the collision is not precise and it gets stuck to the wall for a moment.
Can someone help me?
I hope I explained it well, 'cause I find it hard to explain.
here’s the code I use to move the father:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveComponent : MonoBehaviour {
private float moveHorizontal;
private float moveVertical;
public Rigidbody rb;
public float speed;
void Start()
{
rb = GetComponent ();
}
void Update ()
{
//MOVEMENT
moveHorizontal = Input.GetAxis (“Horizontal”)*Time.deltaTime;
moveVertical = Input.GetAxis (“Vertical”)*Time.deltaTime;
Vector3 movement = new Vector3 (moveHorizontal, 0, moveVertical);
transform.Translate (movement * speed);
}
}