- Home /
rigidbody2d addforce for moving gameObject not work
Hi everyone. My english is bad, but I will try to tell you about my problem. Code (C#):
void FixedUpdate () {
on_tram = Physics2D.Linecast (on_tram_left.position, on_tram_right.position, 1<< LayerMask.NameToLayer("player_l"));
Debug.DrawLine (on_tram_left.position, on_tram_right.position, Color.green);
if(on_tram == true){
on_tram = false;
player_tram.rigidbody2D.velocity = Vector2.zero;
player_tram.rigidbody2D.angularVelocity = 0f;
Vector2 dir = (tram_vec.transform.position - player_tram.transform.position).normalized;
Debug.Log(dir);
player_tram.rigidbody2D.AddForce(dir*500f);
Debug.DrawLine(player_tram.transform.position, tram_vec.transform.position, Color.green);
}
}
So. When game in process and when player cross the line, player not "flying" to gameObject. It make small step in right/left side in moment and after that make ideal vertical jump. And I think player must "fly" for diagonal, but it move very strange. Help me please. You my last hope
Better use raycast for line interception, Try with that
are you getting an error message or is it just not working the way you want?
No, i don't have error message. Its not working like I want.
Ok. I will try with raycast and will write after that!
No. Raycast not help. He push my player in SPAAAACE like spaceship
Agreed. I'm stupid. I wrote limiter of X coor for player, if player speed $$anonymous$$ORE than limit. Thanks for all
Your answer
Follow this Question
Related Questions
add force on topdown bullet 1 Answer
rigidbody2d.addforce for is not working for the x axis 0 Answers
AddForce knockback x axis according to mouse.position more then y axis (2D game) 0 Answers
Rigidbody2d.AddForce behaving odd 1 Answer
Rigidbody2d addforce is weaker at a higher y position. 2 Answers