#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Making an actor graphic scale up and down based on the objects speed

Posts: 478Member
edited November -1
Trying to make an actor graphic scale up and down based on the objects speed of movement.

I need to achieve the following:

1. Have a game attribute game.speed defined in game attributes.

2. If the player actor is moving at a low rate of speed the actor it influences does not change eg 300px wide.

3. At a highter rate of speed the influenced actor width is divided by the speed of acceleration to reduce the width. change attribute - self.sizewidth - game.speed/300

4. Slowing the speed of the actor expands the influenced actor to it's original dimensions gradually. (sort of working by changing the expression above)

I have the speed up / scale down bit working just fine, it's the setting Minimum/Maximum width and scale back up relative to speed I'm having trouble with.

• Posts: 1,803Head Chef, Member, PRO
Constrain Attribute: self.Height = min(300,game.speed/300)
Constrain Attribute: self.Width = min(300,game.speed/300)
• Posts: 8,188Member
/hopes you're not making the same 3D game I am

Dr. Sam Beckett never returned home...
Web: http://www.quantum-sheep.com

• Posts: 478Member
Hey this is great, much simpler than my crappy code, thanks. Mine was very convoluted.

Have the code working, but it's going the opposite to what I would like. How do I make it change from big to small rather than small to big? My speed attribute starts at zero and counts up so my actor only gets bigger as the speed increases. Can I reverse this somehow?

I've adjusted it to constrain the max and minimum width so it does not vanish or get too big like so. (Scales between 300 & 100 pixels only.)

Constrain Attribute: self.Width = min(300,game.speed/15)
Constrain Attribute: self.Width = max(100,game.speed/15)
• Posts: 33Key Master, Member
Constrain Attribute: self.Width = max(100,min(300,(4500-game.speed)/15))
• Posts: 1,803Head Chef, Member, PRO
Constrain Attribute: self.Width = max(100,min(300,(4500-game.speed)/15))

4500 = 300*15.
min(...) -> Your upper limit is 300, so when game.speed is 0, it becomes min(300,300)=300. When game.speed is greater than 0, it gives you the value of (4500-game.speed)/15 to be subject to the max function as it is any number less than 300. When game.speed is less than 0, (4500-game.speed)/15 becomes greater than 300 and is defaulted to 300 by the min function.
This discussion has been closed.