imjustacowlol Posted June 13, 2014 Share Posted June 13, 2014 Hey guys, I'm bussy creating a small video game with a background that is constantly moving from the top of my screen to the bottom. The problem is, as soon as it has completed its simple task of moving from one direction into another, it disappears from the screen. I've been trying for about an hour to get the object back to the top of the screen again, so it can start over moving down again, but unfortinately my poor coding skills haven't managed to do so yet. What I basically want, is that the object gets 'rolled back' for a specific distance when it gets past an imaginairy line. And when it has been rolled back, I want it to start over with going to the bottom of the screen again. And when it gets back to that line, it must role back again etc. etc.. To give you a basic idea of what I want, imagine it like the tracks of a tank if you look at it from the side: 1 segment of the track will go from left to right over the wheels of the tank, as soon as it gets to a specific distance (the last wheel) the track goes down and then it will go from right to left. All segments of the track will do this, and they will all stay perfectly lined up behind each other. Now I do not want to create tank tracks in my game, but the movig background I want could use an similar idea. The script I am using right now to just move it from the top of my screen to the bottom of my screen (might be in diffrent directions for you) is attatched to this post. There are a few not needed lines in there, but that's because I am still working at it myself as well. If you have an idea of what i want, and if you know how to code it then all help would be very much appreciated -Wes Backgroundmovement.lua Quote Link to comment Share on other sites More sharing options...
cassius Posted June 14, 2014 Share Posted June 14, 2014 I don;t know lua script. but can;t you make use of the "turn" function? Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
gamecreator Posted June 14, 2014 Share Posted June 14, 2014 You'll want to use GetPosition to detect when the background went past a certain point and then SetPosition to place it back to the beginning position. I don't know Lua or I'd provide an example but maybe the documentation examples will help. Quote Link to comment Share on other sites More sharing options...
imjustacowlol Posted June 14, 2014 Author Share Posted June 14, 2014 But GetPosition will track where it's current position is. So then I would have to make something similar to this: entity:GetPosition() if self.position==x,y,z then entity:SetPosition(x,y,z) end Would something like that make sense? & btw, lua looks similar to c++ in leadwerks, c++ is just a lot more advanced and there are still some small diffrences in the same code. Quote Link to comment Share on other sites More sharing options...
Charrua Posted June 14, 2014 Share Posted June 14, 2014 hi you have to define a Vec3 variable to hold the position, then you can set/test/change individual values Vec3 Position Position = Entity:GetPosition() Then.... Position.x = Position.x+1 i wrote a simple script using Sin and Cos to simulate a Circular movement, you may change speedFactor on x and y coords Script.xVel=1.0--float x_velocity Script.yVel=1.0--float y_velocity Script.entPos=Vec3 Script.initialPos=Vec3 function Script:Start() --store initial position initialPos = self.entity:GetPosition(false) end function Script:UpdateWorld() --read current position entPos = self.entity:GetPosition(false) --calc new position, relative to the initial one entPos.y = initialPos.y + Math:Sin(Time:GetCurrent()/10.0) * self.yVel entPos.x = initialPos.x + Math:Cos(Time:GetCurrent()/10.0) * self.xVel --update new position self.entity:SetPosition(entPos.x, entPos.y, entPos.z) end create or use a map with one box, and attach this script to the box to create and attach a script (start form zero) read: http://www.leadwerks.com/werkspace/page/tutorials/_/script/creating-your-first-object-script-r110 Quote Paren el mundo!, me quiero bajar. 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.