Raul Posted October 19, 2010 Share Posted October 19, 2010 Okay so here is my code for loading the map: Scene myScene = Scene.Load("abstract::map_1.sbx"); Leadwerks.World.Current.Gravity = new Vector3(0, -20, 0); //??? need to have a look I am pretty sure I do not use the World object right. I have a FPS Controller (made from the LUA and C++ tutorials - works fine on C++) but my Y position rise up frame by frame. Where is my mistake? Quote i5 2.7Ghz, GTS 450, 8GB Ram, Win7 x64; Win8 x64 rvlgames.com - my games RVL Games Facebook Page, YouTube Channel Blitzmax Link to comment Share on other sites More sharing options...
ZioRed Posted October 20, 2010 Share Posted October 20, 2010 I tried the use of World.Current.Gravity and it seems to work normally: using System; using Leadwerks; using Math = Leadwerks.Math; namespace TestLeadwerks2Console { class Program { static void Main(string[] args) { try { Engine.Initialize(DisplayMode.Window, 800, 600); Framework.Initialize(); FileSystem.Initialize(); FileSystem.AbstractPath = "C:/Leadwerks Engine SDK"; } catch { Engine.Terminate(); } Collisions.Set(1, 1, true); Scene scene = new Scene("abstract::test.sbx"); scene.CollisionType = 1; Vector3 debugGravity = new Vector3(0, -20, 0); bool gravity = false; Vector3 start = new Vector3(-1, 1, 0); Controller ctl = new Controller(); ctl.CollisionType = 1; ctl.Position = start; Camera cam = Framework.Layers.Main.Camera; cam.Position = ctl.Position; cam.Move(new Vector3(-2, 0, 0)); cam.PointAt(ctl); Debug.Physics = true; while (!(Window.HasRequestedClose || Keyboard.KeyHit(Key.Escape))) { if (Keyboard.KeyHit(Key.G)) { gravity = true; World.Current.Gravity = debugGravity; } else if (Keyboard.KeyHit(Key.H)) { gravity = false; World.Current.Gravity = 0; } if (Keyboard.KeyHit(Key.) { ctl.Mass = 1; } else if (Keyboard.KeyHit(Key.N)) { ctl.Mass = 0; ctl.Position = start; } cam.PointAt(ctl); Framework.Update(); Framework.Render(); Draw.Text("Gravity: " + (gravity ? "Set" : "Not set")); Graphics.Flip(); } Framework.Terminate(); Engine.Terminate(); } } } May be something in your LUA script? Could you show the controller code? PS: Isn't the gravity already set in the engine to something similar to Y -20 by default? At least on C#headers I don't need to manually set the gravity, just need to set the Mass to the bodies, if you don't really need to adjust more the gravity. Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Raul Posted October 20, 2010 Author Share Posted October 20, 2010 It's not a LUA script. It's c#: using Leadwerks; namespace rvlFPSLeadwerksCsharp { class cPlayer { Controller playerController = new Controller(1.8f, 0.45f, 0.3f, 46f); public Vector3 playerRotation = new Vector3(); public Vector3 playerPosition = new Vector3(); public Vector3 playerHeadPosition = new Vector3(); float playerMove = 0; float playerStrafe = 0; float playerJump = 0; float dx, dy; float cameraPitch, cameraYaw; public void createPlayer() { //controller playerController.Mass = 100; playerController.CollisionType = 1; } public void updatePlayer() { //rotation by mouse int mx = Leadwerks.Graphics.Width / 2; int my = Leadwerks.Graphics.Height / 2; dx = Leadwerks.Math.Curve((Leadwerks.Mouse.X - mx) / 4, dx, 6); dy = Leadwerks.Math.Curve((Leadwerks.Mouse.Y - my) / 4, dy, 6); Leadwerks.Mouse.Move(mx, my); cameraPitch = cameraPitch + dy; cameraYaw = cameraYaw - dx; cameraPitch = Leadwerks.Math.Clamp(cameraPitch, -89, 89); //rotation player playerRotation.X = cameraPitch; playerRotation.Y = cameraYaw; //movement playerMove = Keyboard.IntKeyDown(Key.W) - Keyboard.IntKeyDown(Key.S); playerStrafe = Keyboard.IntKeyDown(Key.D) - Keyboard.IntKeyDown(Key.A); //controller input playerController.Update(playerRotation.Y, playerMove * 3, playerStrafe * 3, playerJump, 500); playerPosition = playerController.Position; playerHeadPosition = playerPosition; playerHeadPosition.Y = playerPosition.Y + (float)1.8; } } } I call player.updatePlayer in the main loop.. Quote i5 2.7Ghz, GTS 450, 8GB Ram, Win7 x64; Win8 x64 rvlgames.com - my games RVL Games Facebook Page, YouTube Channel Blitzmax Link to comment Share on other sites More sharing options...
ZioRed Posted October 20, 2010 Share Posted October 20, 2010 Ok found the problem, you set playerHeadPosition as reference to playerController.Position and not a copy of it, so the last line of your update is not producing what you would mean (that is add an offset to ONLY head position) but it apply the operation to playerPosition (that is reference to playerController.Position as well). To fix your problem you can just clone playerController.Position into playerPosition in your updatePlayer() : ... //controller input playerController.Update(playerRotation.Y, playerMove * 3, playerStrafe * 3, playerJump, 500); playerPosition = playerController.Position.Clone(); playerHeadPosition = playerPosition; playerHeadPosition.Y += 1.8f; ... EDIT: I'd suggest to convert these variables into readonly properties in your class (since you would use them only to read and also add specific methods to move/rotate head or position if you need): class cPlayer { // ... public Vector3 PlayerPosition { get { return playerController.Position.Clone(); } } public Vector3 PlayerHeadPosition { get { Vector3 pos = PlayerPosition; pos.Y += 1.8f; return pos; } } // ... } Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Raul Posted October 20, 2010 Author Share Posted October 20, 2010 thanks for the help. yes, I will add those 'get' and 'set' functions ASAP. i wanted first to test it to see how it works in general.. One more question.. In c++ I had this line: dx = Curve((MouseX()-gx)/4.0,dx,3.0/AppSpeed()); Is for C# something similar to AppSpeed? Quote i5 2.7Ghz, GTS 450, 8GB Ram, Win7 x64; Win8 x64 rvlgames.com - my games RVL Games Facebook Page, YouTube Channel Blitzmax Link to comment Share on other sites More sharing options...
ZioRed Posted October 20, 2010 Share Posted October 20, 2010 Yes it is Timing.Time and you have to call Timing.Update() before Framework.Update() in your loop, as described here. Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Raul Posted October 20, 2010 Author Share Posted October 20, 2010 Thanks again. Quote i5 2.7Ghz, GTS 450, 8GB Ram, Win7 x64; Win8 x64 rvlgames.com - my games RVL Games Facebook Page, YouTube Channel Blitzmax 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.