Moving in a 3D space #13
-
Hi ! In my free time I have fun using this superb game engine to develop a small game which will be ported to GameCube in the end. However, Iwant to be able to move a character in a 3D world with a third person view. When I use rotation to look in another direction and try to move my character forward, it does not move in the direction I am looking, but moves on all 3 axes as originally without the rotation. I guess I'm not doing it the right way, since at the moment I'm trying to move the character, when I should rather be moving the map? But being a beginner and doing this in my free time as a hobby, I unfortunately don't know how to use the right functions to move my character. Infos about the code Default Scene name : SC_Default GetPosition() stored in variable newPos Thank you in advance for your help |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
I managed to solve my problem! To do this, I constantly retrieve the vector value of my current position with GetPosition(), Now my character moves well in the direction I point him. Same procedure for moving from left to right but using GetRightVector() instead of GetForwardVector(). Now I have a new problem... I can move forward, backward, left, right, but, when I want for example to move at an angle (forward and left at the same time), I moves either only forward or only to the left, depending on which keyboard key was last pressed. And I admit that I don't know how to fix this. Part of the code that I use to move my caracter : local newPos = self.poule:GetPosition()
-- Avancer
if (Input.IsKeyDown(Key.Z)) then
directionPoule = self.poule:GetForwardVector()
directionPoule = -directionPoule * self.vitesse * deltaTime + newPos
end
-- Reculer
if (Input.IsKeyDown(Key.S)) then
directionPoule = self.poule:GetForwardVector()
directionPoule = directionPoule * self.vitesse * deltaTime + newPos
end
-- Aller à gauche
if (Input.IsKeyDown(Key.Q)) then
directionPoule = self.poule:GetRightVector()
directionPoule = directionPoule * self.vitesse * deltaTime + newPos
end
-- Aller à droite
if (Input.IsKeyDown(Key.D)) then
directionPoule = self.poule:GetRightVector()
directionPoule = -directionPoule * self.vitesse * deltaTime + newPos
end
self.poule:SetPosition(directionPoule) |
Beta Was this translation helpful? Give feedback.
-
Hi, quick update on my progress. So, compared to last time I managed to use the RotateAround() function which allowed me to move the camera up and down around my character in order to finally be able to look up and/or down without that my character doesn't fly towards the direction I'm looking lol. I also tried to model terrain in Blender, I added a texture and imported it into my default scene. I also added a function that allows you to manage the double jump, which counts the number of jumps while the character is in the air, and once the chosen number is reached (2 in my case), prevent the character from jumping again as long as it has not touched the ground and/or a surface on which collision is activated. I'm moving forward slowly and little by little I'm discovering the joys of developing a video game and I find it very exciting! Attached is the .zip file of my work so far. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the encouragement. I created a scene called 'SC_Assets' in which I added several nodes (a cube, a ball, a tree, etc.) and I am trying to make them appear in my SC_Default when I press for example the X button to make a ball appear, the Y button for a tree etc.. Until now I have managed to import a complete scene with all the nodes , but I can't import only one node that I have chosen in the scene. I used the LoadAsset() functions to load the scene I want, and Instantiate() to link it to my SC_Default, and then AddChild to make my scene appear at the desired location. I guess my mistake is because I'm using Instantiate() to bind the whole scene and not another function to pick just one element from a scene, but I don't know which function to use to achieve the desired result. |
Beta Was this translation helpful? Give feedback.
I'm glad you were able to solve your original problem!
I think you are having trouble moving at an angle because you are overwriting directionPoule. If Z is pressed, then you set directionPoule, but if Q is also pressed then you are resetting directionPoule before you ever set the new position.
Maybe something like this would work: