3
« on: August 24, 2013, 01:27:50 pm »
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..
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