简体   繁体   中英

Unity3D: Left Joystick Translation Depending on Facing Direction

I'm hitting a wall on this really simple problem... I know there has to be a simple solution, but I'm not exactly sure what it is. I'm prototyping for a game jam -- my game is a top down, 3D twin sticks style game. The right stick rotates the player and the left stick controls the movement. The movement is done via animations in Mecanim -- I have forward/backward/strafing setup and blended.

My problem is right now it moves like Resident Evil -- "up" on the joystick drives the character forward no matter what direction she is facing. I need to translate "up" on the joystick to be relative to the world -- not the player (ie: if facing right, "up" should make her strafe left). What am I trying to find? I'm pretty sure there's some built it translation that I need to call...

I'm using Unity and am sending Horizontal and Vertical values between -1 and 1 to Mecanim. I need to translate these values based on character rotation so "up" moves the character toward the top of the screen based on it's original rotation.

图片1

图片2

图片3

Ok it sounds like the trouble is coming from the fact that you are translating using the models forward vector. Most of the time this is what people want but in your case you just want to move the character based on the world space. My suggestion would to get back the characters position in the world and just add the values to the position vector. Im not entirely sure how its done in unity but if I wanted to get a modelspace position in to worldspace in order to do something with it I would multiply that vector by the worldmatrix which will take that point from model space in to worldspace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM