University of Southern CaliforniaUSC
USC ICT TwitterUSC ICT FacebookUSC ICT YouTube

Animate objects pawns | General SmartBody Discussion | Forum

Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Animate objects pawns
September 22, 2015
3:01 pm
Avatar
Member
Members
Forum Posts: 14
Member Since:
July 25, 2015
sp_UserOfflineSmall Offline

In my project i've some pawns like boxes and i need to animate them something like move them in X axis (as example create a loop move from -30.0 to 30.0 and from 30.0 to -30.0). I've tryed to do that using an loop statement but this solution doesn't because script never ends.
Someone know how to implement this kind of features on Smartbody or any script sample to do that?

September 22, 2015
6:11 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

Here you go:

 

scene.createPawn("pawn0")

class SimpleScript(SBScript):
   curTime = 0.0
   dt = .016
   curX = -30
   dx = .1

   def update(self, time):
      if self.curTime + self.dt < time:
         pawn = scene.getPawn("pawn0")
         curPos = pawn.getPosition()
         self.curX = self.curX + self.dx
         if self.curX > 30.0:
            self.curX = 30.0 - (self.curX - 30.0)
            self.dx = self.dx * -1 # reverse the movement
         else:
            if self.curX < -30.0:
               self.curX = -30.0 + (self.curX + 30.0)
               self.dx = self.dx * -1 # reverse the movement
         curPos.setData(0, self.curX)
         pawn.setPosition(curPos)
         self.curTime = time

myscript = SimpleScript()
scene.addScript("simple", myscript)

Forum Timezone: America/Los_Angeles

Most Users Ever Online: 733

Currently Online: jiangringgaard7, groth23rowland, mcclain06kearney, bugge59mackinnon, williamson15mogensen, raskrask1, JosephRoper17, heavenlyliar6390
93 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

jwwalker: 80

jyambao: 52

rbaral: 47

adiaz: 30

WargnierP: 29

lucky7456969: 28

mbarros: 28

avida.matt: 26

JonathanW: 24

laguerre: 23

Member Stats:

Guest Posters: 69

Members: 122211

Moderators: 3

Admins: 4

Forum Stats:

Groups: 1

Forums: 5

Topics: 531

Posts: 2495