Sticking to a wall

Hi,

This has to be simpler than I’m making it. Also, my approach doesn’t work.

Think of the Spiderman game franchise. Specifically, the way he crawls on the walls. That’s pretty simple, right? The player object aligns to the current normal, and then rotates to match the current direction. At least, I assume that’s the case.

But so far, every attempt I’ve made to do this fails miserably. The best example I have found so far of this is the guy walking on the worlds, in the Locomotion System. But the scripts that handle that look like overkill for something simple like this.

Is there a simple way to make this work? Any suggestions?

I’m not posting any of my code here, because…

  1. It doesn’t work
  2. I’d like to know how I should do this, independent of my own attempts.

So any approach that works, is what I’m looking for.

Thanks!
-Chilton

this might not help you but make what you need to “stick to the wall” child on collision

Would that work? or am I thinking of somthing else…

You’ll want to use “OnCollisionEnter” because that will give you data about what your character is sticking to, including (I hope for you) the angle of the surface and the position of contact.

With that info (position of contact and angle of contact) you should be able to position and angle your player correctly with transform.position and transform.rotation.

That’s vague, but it’s complex and I’m just figuring it all out myself. That should point you in the direction of WHAT you need to learn.

Hope that helps.

Oh, and by the way, I just noticed you’re in San Antonio. We’re having a Unity User Group meeting here in Austin on Sunday the 24th if you can get up here. It will be informal, relaxed networking get together sort of thing, but if you bring a laptop then maybe you can get some help with your project. Here’s the url for the group:

http://groups.google.com/group/unity3daustin

Hi,

That’s an interesting idea, but it’s not exactly what I need, because I need it to then stick to the next wall, or the ground, if I drive from one to the next.

-Chilton

Hi,

I might use collisions for this, and I might use a raycast for it.

What I’m confused on though is how to take my existing rotation and relative ‘up’, and translate that to the normal vector for the other surface, while retaining my current rotation.

-Chilton

Hi,

That rocks! I’ll see what I can do to make it.

-Chilton

Hi,

I’ve figured it out, and I’ll post a demo of it shortly, along with some sample code. Cross Product was the answer.

-Chilton

I’ve been lurking these forums for a while, but I must say I’d be very interested to see what you come up with. I am myself looking for a way to snap an object’s Y axis to a vector which can change all the time. I solved surrounding issues for now (movement, smooth camera snapping, etc) but the correct rotation towards my (correctly found) vector eludes me. Looking forward to that Cross Product solution of yours.