Currently I have a simple 2d game where a cube moves along the x-axis and has the ability to jump. I have a rigidbody setup on the moving cube and i also have other stationary cubes to act as objects. But for some reason when i jump on the side of a cube and continually push against it, it doesnt fall, it just sits there floating againt the obstacle, seemingly by a large amount of friction against the two cubes. Im stuck and would love a sense of direction and understanding of why this is occuring and how to fix it. Heres my code for the moving block.
using UnityEngine;
using System.Collections;
public class movement : MonoBehaviour {
// Use this for initialization
private Transform box;
private bool isjumping = false;
void Start () {
GameObject go = GameObject.FindGameObjectWithTag("Player");
box = go.transform;
Camera.main.transform.position = new Vector3(box.position.x,box.position.y + 3,box.position.z -5);
}
void FixedUpdate(){
if(Input.GetKey(KeyCode.RightArrow) == false & isjumping == false){
rigidbody.velocity = new Vector3(0, rigidbody.velocity.y, 0);
}
if(Input.GetKey(KeyCode.LeftArrow) == false & isjumping == false){
rigidbody.velocity = new Vector3(0, rigidbody.velocity.y, 0);
}
if(Input.GetKey(KeyCode.RightArrow) == true){
rigidbody.velocity = new Vector3(5f, rigidbody.velocity.y, 0);
}
if(Input.GetKey(KeyCode.LeftArrow) == true){
rigidbody.velocity = new Vector3(-5f, rigidbody.velocity.y, 0);
}
if(Input.GetKeyDown(KeyCode.UpArrow) == true & isjumping == false){
rigidbody.velocity = new Vector3(rigidbody.velocity.x, 5, 0);
isjumping = true;
}
}
void OnCollisionEnter(){
isjumping = false;
}
void Update(){
if(Camera.main.transform.position.x > box.position.x + 4){
Camera.main.transform.position = new Vector3(box.position.x+4,Camera.main.transform.position.y,box.position.z -5);
}
if(Camera.main.transform.position.x < box.position.x - 4){
Camera.main.transform.position = new Vector3(box.position.x-4,Camera.main.transform.position.y,box.position.z -5);
}
if(Camera.main.transform.position.y < box.position.y ){
Camera.main.transform.position = new Vector3(Camera.main.transform.position.x,box.position.y ,box.position.z -5);
}
if(Camera.main.transform.position.y > box.position.y + 2 ){
Camera.main.transform.position = new Vector3(Camera.main.transform.position.x,box.position.y +2 ,box.position.z -5);
}
}
}
I’ve asked this question previously, unfortunately with no response. Any help whatsoever would be greatly appreciated.
Don't double post. If you edit your question or if you add a comment it will automatically bump the question to the top. I've deleted your "old" question. If you don't get an answer that could mean: - No one has seen the question or at least nobody who could answer the question. - The question might be too difficult to understand / comprehend. Usually people post comments to ask for clarification but that's not always the case. Keep in mind that a lot people live in different timezones than you.
– Bunny83I apologize, I didn't know how to make my question more visible since no one had viewed it for about 2 days straight.
– asfdasc