Hello Guest

Author Topic: RPG Style 2d Collisions - Don't care about Physics - Need Help Please  (Read 6191 times)

CVogel

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Ok, I'm a Unity Newb. and I'm a 2d Toolkit Newb. And I'm a programming Novice. and what I'm trying to do seems WAY harder than It should be. I sure hope there's an easy solution that someone can guide me towards.

I have a basic sprite background covering the screen of my demo game.
I have an animated sprite Hero. The hero plays animations and walks around just fine.
I have a rock sprite imported from the Demo Sprites (which I edited to have a Boxtrimmed Collider)

My Hero and My Rock are on the same Z plane. I just want my hero to not be able to walk through the rock...

I've tried rigid bodies and box colliders and character controllers in every possible way I can figure out. I just don't know what I'm doing. I can tell in the scene editor that the box collider outlines will in fact overlap so I'm pretty sure a collision is detected, my character just doesn't stop moving when that happens or clamp to the edge of the object.

I of course haven't wrote any script to cause that clamping, I was hoping there was a way to make objects collide without that. I'm guessing the answer there is Physics. I don't want any physics interaction besides stopping movement... But If it's one or the other, I'll take the easiest solution for now.

As for how I'm moving my hero sprite, I'm using code like this..
Code: [Select]
if (up && !left && !right)
{
if (!anim.IsPlaying(walkup)) anim.Play (walkup);
transform.Translate( Vector3.up * (Time.deltaTime * HeroSpeed));
}

I'm sure questions like this have been asked here a thousand times. I really did search the forums and I've been reading posts for the last hour, and I just can't seem to figure it out.

Thanks if you can help.

Chris

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: RPG Style 2d Collisions - Don't care about Physics - Need Help Please
« Reply #1 on: August 24, 2013, 09:22:56 pm »
Its not that hard. You obviously need to learn how to make a character controller.
Example attached - this is not supported, just a quick and dirty example of how to do this.

Bascally if you "translate" its not going to consider collisions. You'd use the character controller.Move to achieve the same result, more or less, but this will nicely slide around colliders.

CVogel

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: RPG Style 2d Collisions - Don't care about Physics - Need Help Please
« Reply #2 on: August 25, 2013, 05:11:51 am »
Thanks I'll check out that package and study how it works.

CVogel

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: RPG Style 2d Collisions - Don't care about Physics - Need Help Please
« Reply #3 on: August 25, 2013, 08:00:36 am »
Using the character controller in that way was much, much simpler than I envisioned. I also realize now that this was solely a "Unity" question and not a 2DTK question. I for some reason thought that 2DTK had it's own way of handling collision which if why I asked here instead of in the main Unity forums, and also why I didn't start by going through the Unity Docs.

Thanks for helping!
« Last Edit: August 25, 2013, 08:52:39 am by CVogel »