Haydenmango Posted April 11, 2014 Share Posted April 11, 2014 Hi everyone. So this may be basic for some people but I have been having some trouble making my character move forward depending on where the camera is facing. I can make my character rotate and even move, but not consistently forward. I am not using Navmesh (the player is floating underwater) so I don't think SetInput() would work. I have tried messing with other scripts and functions but I am not the best at math yet so any help with this would be appreciated. Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
Rick Posted April 11, 2014 Share Posted April 11, 2014 SetInput() has nothing to do with the Navmesh. SetInput() is how you move the character controller on the ground based on your inputs (generally for the player character you use SetInput() and for AI that use the NavMesh you use GoToPoint() or Follow()), however it won't work right for under water situations. That's a very key piece of information that you might want to put in your title because it changes how you have to do things. 1 Quote Link to comment Share on other sites More sharing options...
DudeAwesome Posted April 11, 2014 Share Posted April 11, 2014 there should be a 3rd person script per default in the script folder. take a look and read the code Quote It doesn´t work... why? mhmmm It works... why? Link to comment Share on other sites More sharing options...
Haydenmango Posted April 11, 2014 Author Share Posted April 11, 2014 Thanks for the clarification Rick. I wasn't sure if SetInput() was connected to the Navmesh or not; all I could tell was that it wasn't working in the air/water. I'm so tired I can't figure out how to change the title if I even can, hopefully someone will understand it if not I may change it later on today. @DudeAwesome I know there is a 3rd person camera script and a 1st person character script but neither of them contain the answer. They only utilize SetInput(). Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
YouGroove Posted April 11, 2014 Share Posted April 11, 2014 @DudeAwesome : This is not real TPS camera but just X-Z camera mainly, not a camera like in mmo games or real TPS games. Correct me if i'm wrong. Would be better for LE3 in the future to have to have for new comers and non coders, essential cameras ready to use : - minimal camera FPS (not the FPS demo that is full of other code) - Real TPS camera Just a suggestion. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Haydenmango Posted April 11, 2014 Author Share Posted April 11, 2014 yeah a simple Entity:Forward(entity,amount) would be nice. Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
bandrewk Posted April 11, 2014 Share Posted April 11, 2014 yeah a simple Entity:Forward(entity,amount) would be nice. Just rotate the entity to your needs and call Entity::Move(x,y,z). Take a look at: http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/entity/ http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/entity/entitymove-r165 For underwater simulations you probably want to turn off the gravity for the object and play with physics parameters such as friction. 1 Quote Link to comment Share on other sites More sharing options...
Haydenmango Posted April 11, 2014 Author Share Posted April 11, 2014 The problem is after I rotate my entity I need to change my movement values somehow to accommodate for the change in rotation. Example- if window:KeyHit(key.w) then self.move.z = 1 end self.entity:Move(self.move) now when I rotate I am still moving the same direction, no longer Forward. This is my issue. I can move fine in the water without rotation. Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
Haydenmango Posted April 11, 2014 Author Share Posted April 11, 2014 wow.... so I set Move(self.move,false) and it works! I wasn't moving in local space. Sorry about that and thanks for the responses everyone! Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
Rick Posted April 11, 2014 Share Posted April 11, 2014 Note that Move() will kill any physics if you want that or not. 2 Quote Link to comment Share on other sites More sharing options...
Joshua Posted April 11, 2014 Share Posted April 11, 2014 I calculate movement a different way than using SetInput(...). Each object in my game has an UP vector and a Right vector. The right vector is calculate every frame. the Up vector is assigned when the object is created. When I want to move my object forward or backward, depending on the rotation of my camera, I calculate the objects forward vector and move the object in that direction by a given speed. In the folowing code snippet, the view vector is a Vec3 indicating where the object is facing. The allowY variable limit the ability to move the object in the Y plane, based on the objects rotation. // ------------------------------------------------------------------ // Moves the object forward or backward depending on the given speed. // ------------------------------------------------------------------ void esMovableObject::Move(float speed, bool allowY) { // Get the current view vector. Vec3 l_vVector = m_vView.Subtract(m_vPosition).Normalize(); // Add the current view vector to the position. m_vPosition.x += l_vVector.x * speed; m_vPosition.z += l_vVector.z * speed; // Add the current view vector to our view. m_vView.x += l_vVector.x * speed; m_vView.z += l_vVector.z * speed; if(allowY) { m_vPosition.y += l_vVector.y * speed; m_vView.y += l_vVector.y * speed; } } // end void esMovableObject::Move(float speed, bool allowY) // ----------------------------------------------------------------------------------------- Here is an example of how I accomplish strafing with my objects. The m_vRightVector is updated every frame in the base object's update method. This is accomplished from the following code. // ---------------------------- // Updates the esMovableObject. // ---------------------------- void esMovableObject::Update(float deltaTime) { // Update the Right Vector of the esMovableObject m_vRightVector = -m_vView.Subtract(m_vPosition).Cross(m_vUpVector).Normalize(); } // end void esMovableObject::Update(float deltaTime) // ----------------------------------------------------------------------------------------- // ------------------------------------------------------------ // Moves the object left or right depending on the given speed. // ------------------------------------------------------------ void esMovableObject::Strafe(float speed) { // Add the strafe vector to our position. m_vPosition.x += (m_vRightVector.x * speed); m_vPosition.z += (m_vRightVector.z * speed); // Add the right vector to our view. m_vView.x += (m_vRightVector.x * speed); m_vView.z += (m_vRightVector.z * speed); } // end void esMovableObject::Strafe(float speed) // ----------------------------------------------------------------------------------------- Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.