Jump to content

How to make a continiously moving object?


imjustacowlol
 Share

Recommended Posts

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 smile.png

 

-Wes

Backgroundmovement.lua

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Paren el mundo!, me quiero bajar.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...