- Home /
How to disable this "friction"?
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. $$anonymous$$eep in $$anonymous$$d that a lot people live in different timezones than you.
I apologize, I didn't know how to make my question more visible since no one had viewed it for about 2 days straight.
Answer by Bunny83 · Nov 23, 2013 at 03:48 AM
Well, first of all if you continously push agains the wall, that's the normal behaviour. Keep in mind that gravity is nothing but a constant force downwards. The resulting velocity is against the wall, so you will have friction between your player and a vertical wall.
All colliders can have a PhysicMaterial which describes the behaviour of the collider. If you want no friction at all, apply a physics material to the wall with no friction (all set to 0) and make sure the player's collider has a material with mode multiply.
Thanks. I was assigning zero material but I was not using multiply mode but average so it was not working as intended. Thank you.
Answer by Max_power1965 · Dec 15, 2015 at 09:52 PM
There is new unity component called platform Effector 2D that will allow you to do that: more info here: http://docs.unity3d.com/Manual/class-PlatformEffector2D.html