#Rigidbody
1 messages · Page 1 of 1 (latest)
Sure thing
Turn off the freeze position while kinematic
and how do you move the character, set position or Rigidbody move to?
That option isn't available in Kinematic mode.
I can provide my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
// Private variables.
private Rigidbody2D rigidBody2D;
[Header("Movement Properties")]
public float speed = 500f;
// Start is called before the first frame update.
void Start()
{
// Set private components part of the game object.
rigidBody2D = GetComponent<Rigidbody2D>();
}
// Update is called once per frame.
void Update()
{
// Collect movement axis from `Input`.
float horizontal = Input.GetAxisRaw("Horizontal"); // Add smoothing.
float vertical = Input.GetAxisRaw("Vertical");
// Create a `Vector2` for velocity and normalize it.
Vector2 direction = new Vector2(horizontal, vertical);
direction = direction.normalized;
// Apply the `Vector2` to the `Rigidbody` velocity.
rigidBody2D.velocity = direction * speed * Time.deltaTime;
}
}
Huh, in the video its checked and not greyed out
Same result sadly.
can you show me a screenshot of the player gameobject?
Sure thing.
ill quickly setup a playground to emulate your stuff
can you send me your playerscript? if i type that up myself its gonna take a minute longer 😄
Sure thing, it should be above.
oh lol im dumb 😄
Nahh, you're good
alright, ill ping you when im done
Does your grid have a rigid body on it
Oh wait right, why does it even have that, why didnt I think about that lol
@rain dust ^ lemons question could solve that
your walls dont need the rigidbody
It was added automatically to use a composite collider.
Looks like the grid doesn't have any rigid bodies on it.
Just the tilemaps do.
I use a tilemap collider, then tick "Used by Composite" to make it one seamless collider.
Otherwise the player gets stuck on the seams.
Ok they it’s your player?
Because rewatching it, the player is moving not the tile maps
Take the camera off the player
See which one moves
It's the tilemap that moves.
The player's positon is stationary and it's position isn't modified outside of the code attached above via rigidBody.velocity
I have now replicated your project, ill ping you if i find a solution
It appears yours and mine are the same, unless I'm missing something.
I'm starting to wonder if two kinematic objects can even collide with eachother.
lol im confused as to how you could do this without it being dynamic
My rigid body on the player is Kinematic and I self program the movements since I don't want physics applied.
Make the player dynamic, gravity scale to 0
if the tiles are on dynamic, they fall on their own
with player on dynamic with 0 gravity
Yeah I just asked ChatGPT.
You need to program the collisions yourself between two Kinematic objects, so it looks like Dynamic is for me.
I mean you can use unity for collisions, or you can program your own
but I feel like you might be missing something if you're not trying to program your own physics
Yeah, not sure I'm at that stage yet.
I'll stick to Dynamic.
I appreciate the help you two!
No problem! Glad we could help
if you need help with the player let me know
Nope, all good now!
No leftover bugs.