|
Hi! I just started using unity recently and I already figured out how to do a few simple things. My problem is as follows: I would like a script that would make the character be able to walk on walls (in other words, change gravity to the opposite of the character's normal) all while being able to use mouselook as well. I found this code, which looks and works great, except for the fact that the "a" and "d" keyes turn the character instead of making it sidestep. Any help would be appreciated! Here's the code I found earlier. Thanks in advance! :D By the way, the script is added to an empty which has rigid body and a box collider.
(comments are locked)
|
|
Alright. First, to disable rotation with the a and d keys, find these lines and comment them out: Now, to make it so that you strafe, find this line: And under it add: That should work. If you are strafing, but in opposite directions, add a " That's great, thanks! It works well, but there's one problem that I can't figure out. Everything works except for the horizontal mouse look. I can move my character forwards backwards, strafe and jump. It also does the gravity thing, and I can make the camera look up and down. The only thing it's not letting me do is rotating the character using the mouselook script. What could the problem be? Thanks in advance!
Jun 10 '12 at 02:57 PM
TheTimeLord
Right, so when you edited the script, we disabled the the horizontal axis. To get it to map to the mouse, you should be able to grab the horizontal mouse information from Input. Try changing those first two lines you commented out to read like this: var turn = Input.GetAxis("Mouse X') * turnSpeed * Time.deltaTime; turnAngle = (turnAngle + turn) % 360; That might be your ticket, though you'll probably have to tweak whatever the value of "turnSpeed" is. If turning with the mouse still feels strange, trying removing the " * Time.deltaTime" bit from that line and see if it works any better.
Jun 10 '12 at 08:11 PM
drizztmainsword
(comments are locked)
|
|
Thanks it worked great! I didn't realize it could have been something as small as one name but hey, that's code for you! :D
(comments are locked)
|

can you use lookAt while walking on the wall? iam using a similar script and cant use lookat while wall walking any tips?
LookAt makes it so that the Y axis of whatever transform you are affecting points as close to "up" in worldspace as possible.
If I had to guess, it's probably using Quaternion.SetLookRotation() to do this. You should be able to use this function to manipulate whatever it is you want to look in a specific direction and have the Y axis point towards the character's relative "up."
for example (not real code):
You'll have to do some work to get the specifics, but that is most definitely the function you want to work with. Check it out in the Scripting Reference.
thanks for the hint this is what iam using now
its working when i look at the object on the original floor but when i try look at an object on the wall i am currently walking on my character is just shaking
my actual question is on this link
Got it to work!! used raycast and Rotate