Unity'de kullanılan nesne yere düşerken karakter yere düşmüyor

Eki Görüntüle 1620208

Kusura bakmayın daha yeniyim unity'de dediğiniz yer burası mıydı?
Evet burasıydı. İlginç gerçekten böyle olmaması gerekiyor. Yeni bir 2D obje oluşturup (atıyorum bi square vs) ona rigidbody ekleyebilir misiniz o düşüyor mu aşağı bakalım. Ya da düşen başka bir obje ile rigidbodysinin ne farkı var bunun
 
Simulated tikini kaldırıp denediğimde de bir şey değişmedi.

C# kodlarında bir hata olabilir mi ?
Eğer kodlarda bir şey rigidbodynin velocity'sine ya da pozisyonuna müdahale ediyorsa olabilir. Karakteri hareket ettiren kodu atar mısınız? Ya da karakterin pozisyonuna müdahale eden ne kod varsa
 
1672585980529.png


Evet Hocam yeni objeler düşüyor.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterController : MonoBehaviour
{

[SerializeField] private float speed = 10f;
[SerializeField] private float jumpforce = 5f;
private Rigidbody2D _rigidbody2D;
private Animator _animator;

private bool grounded;
private bool Started;
private bool jumping;


private void Awake()
{
_animator = GetComponent<Animator>(); //caching
_rigidbody2D = GetComponent<Rigidbody2D>();
grounded = true;
}

private void Update()
{
if (Input.GetKeyDown("space"))
{
if (Started && grounded)
{
_animator.SetTrigger("jump");
grounded = false;
jumping = true;
}
else
{
_animator.SetBool("GameStarted", true);
Started = true;
}
}
_animator.SetBool("Ground", grounded);
}

private void FixedUpdate()
{
if (Started)
{
_rigidbody2D.velocity = new Vector2(speed, _rigidbody2D.velocity.y);
}

if (jumping)
{
_rigidbody2D.AddForce(new Vector2(0f, jumpforce));
jumping = false;
}
}

private void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.CompareTag("Ground"))
{
grounded = true;
}
}
}
 
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class characterController : MonoBehaviour
{
public float speed = 1.0f;
private Rigidbody2D r2d;
private Animator _animator;
private Vector3 charPos;
private SpriteRenderer _spriteRenderer;
[SerializeField] private GameObject _camera;
private int sayi;

void Start()
{
_spriteRenderer = GetComponent<SpriteRenderer>();
r2d = GetComponent<Rigidbody2D>();
_animator = GetComponent<Animator>();
charPos = transform.position;
sayi = 1;
}

void FixedUpdate()
{

sayi = 2;

// 50fps fizik hesaplamaları burada yapılacak bu ise 2 kere çalışıyor bundan dolayı hesaplama yapamıyor
//r2d.velocity = new Vector2(speed, 0);
}


void Update()//per frame 120 defa çalışıyor fps kadar
{





charPos = new Vector3(charPos.x + (Input.GetAxis("Horizontal") * speed * Time.deltaTime), charPos.y);
transform.position = charPos;
if (Input.GetAxis("Horizontal") == 0.0f)
{
_animator.SetFloat("speed", 0.0f);
}
else
{
_animator.SetFloat("speed", speed);

}
if (Input.GetAxis("Horizontal") > 0.01f)
{
_spriteRenderer.flipX = false ;
}

else if (Input.GetAxis("Horizontal") < -0.01f)
{
_spriteRenderer.flipX = true;
}


sayi = 3;
Debug.Log("Update" + sayi);


}
private void LateUpdate()
{
sayi = 4;
// _camera.transform.position = new Vector3(charPos.x,charPos.y,charPos.z-1.0f);
}
}
 
Eki Görüntüle 1620212

Evet Hocam yeni objeler düşüyor.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterController : MonoBehaviour
{

[SerializeField] private float speed = 10f;
[SerializeField] private float jumpforce = 5f;
private Rigidbody2D _rigidbody2D;
private Animator _animator;

private bool grounded;
private bool Started;
private bool jumping;


private void Awake()
{
_animator = GetComponent<Animator>(); //caching
_rigidbody2D = GetComponent<Rigidbody2D>();
grounded = true;
}

private void Update()
{
if (Input.GetKeyDown("space"))
{
if (Started && grounded)
{
_animator.SetTrigger("jump");
grounded = false;
jumping = true;
}
else
{
_animator.SetBool("GameStarted", true);
Started = true;
}
}
_animator.SetBool("Ground", grounded);
}

private void FixedUpdate()
{
if (Started)
{
_rigidbody2D.velocity = new Vector2(speed, _rigidbody2D.velocity.y);
}

if (jumping)
{
_rigidbody2D.AddForce(new Vector2(0f, jumpforce));
jumping = false;
}
}

private void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.CompareTag("Ground"))
{
grounded = true;
}
}
}
if (Started)
{
_rigidbody2D.velocity = new Vector2(speed, _rigidbody2D.velocity.y);
}
satırını yorum satırına alırsanız karakteriniz düşüyor mu? Sorun burada mı diye anlamak için soruyorum
 

Geri
Yukarı