Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
[SOLVED] (Thanks to Just_in_Case) I've been trying for a long time but can't find a solution. How would I move something left or right, relative to the player's 3D position/rotation please? I my game, I've made a special top-down (bird's eye) camera which rotates with the mouse, the player moves to wherever the mouse is pointing. The player is always facing North as the map rotates. I want the character to strafe/side-step left and right by pressing keys (like the "a" and "d" keys of the 1st Person Camera, for example) but it just doesn't seem possible - everything I've tried always moves the character relative to the map (global), rather than relative to the character themselves (local). How would I do this please? I've uploaded the demo to explain it better (updated link - Bird'sEyeShooter.exe)... https://veganpete.itch.io/srateg... Character movement forwards works, just left and right strafe needs solving. Thank you. |
||||
|
The URL says file not found. If you are using javascript, then you can simply get the current position of your character using the command. var pos = ccbGetSceneNodeProperty(character,"Position"); then you can simply use the `pos` variable to get the x,y,z positiion of the player and can then add or subtact the strafe amount to it and then set the position to the character.
you can do the same for strafing to the other side, instead of adding the strafeAmount just subtract it. Hope it makes sense and helps you out. |
||||
|
Ah, I see what's happened, the host is giving me the link but then it's automatically deleting the file because it's a win.exe Thanks for the help Just_In_Case, nice one - I'll give that a try. Really appreciate your support. |
||||
|
Tried the code you posted, unfortunately it's causing the same issue - it's not really strafing the character, it just moves him in the same direction, no matter which way he's facing. I think I need to check rotation, not just position. I'll keep playing around to see if I an nail it. Thanks again. |
||||
|
ooo, so you want to strafe left and right on the basis of player facing direction. You probably need to do some trignometry here, to get the Forward and Right vector for the player and then based on these two vector update the player position.
the above code should work for you. It doesn't matter in which direction the player is facing, it will always Strafe Left and Right on the basis of the player's rotation(facing direction). Let me know if you need a working example file that uses this code. You can also use the same code above to create forward and backward movement as well for the player facing direction. Hope this helps :) |
||||
|
Thanks Just_In_Case It's looks promising but it still doesn't quite seem to work properly for me (almost). The new code, for me, makes the player sort of walk in a clockwise U-shape when I press A, and an anti-clockwise U-shape when I press D. Then if I keep holding the key, he starts walking backwards. I've probably done something wrong - I couldn't get it to work - so I modified it - I've probably screwed it up somewhere along the way?... Really appreciate the notes you've put on the code you posted - very helpful. Thanks! I'll send a donation for you hopefully tomorrow. |
||||
|
Do you think var forward could be the problem? |
||||
|
Hi there, my apologies, I checked the code and found that we have to convert the rotation of the player to radians, CC uses degrees. While the code that I provided it expect the rotation rot.y to be in radians. For the var forward we didn't used it, it won't cause any issue.if you want you can completely remove it. I included it in case you want to create forward and backward movement on the basis of player facing direction. Here is the corrected/updated code:-
Use the above code for Left and for right change the negative sign to positive for pos.x and pos.z Attached is also a test sample file, you can move to left and right using the A and D, and can rotate the player with F https://cdn.discordapp.com/attac... Hope this is what you are trying to do. |
||||
|
Thank you for this Just_In_Case - you are a shining star! This script will be very useful for me. By the way, your "Buy me a coffee" button doesn't seem to be working on your github page. I'll make a €20 donation through itch.io instead. Thanks again for all your help. |
||||
|
Works perfectly! Thank you. I've included a quick Bird's-Eye Shooter demo here... https://veganpete.itch.io/srateg... Use Mouse to aim (no shoot yet). Mouse-distance from player determines walk/run/sprint speed. W and S walk forwards/backwards. A and D strafe left/right and circle around the aim-point. |
||||
|
Thanks a lot @VP for your support, I tried the Demo, but for me the movement is not working, I am unable to move with keyboard, the cube only moves with mouse aiming. Maybe there is something missing not sure. Also I would like to invite you to test out my custom engine that I have been creating for past few weeks. It is not a complete game engine, but it is slowly getting shape and look and feel of an engine. Let me know if you want to try it out, and I will send you a copy of it in it's current state. |
||||
|
Just tried the updated version, and it works pretty good, I can shoot and move with WASD, Also liked that you did updated the laser sight so that it won't disappear when cursor is aimed at a very far distance, very clever. Glad that it is coming out pretty nicely. |
||||
|
Thank you Just_In_Case! Yes, it's coming along. I limited the camera view angle to 90degrees down and 45degrees up so the view should never leave the play area. I'm just finishing making a quick code now to adjust the camera height and z-position, with the mouse, so the player never goes off-screen when the camera-angle changes. Yes please! I'd love to try your game-engine. If you can sent a link to my proton email, that'd be great. I no longer have access to my gmail/google account. Thank you! |
||||
|
Done, sent you a download key to the game engine uploaded it on itch.io as well. Hope you like the prototype. |
||||
|
Thank you! |
|