The current information on the status of this problem can be seen within the above file.
ORIGINAL POST:
Using sumo, gravity set to 0.00
Simple scene:
A big box, in that box, a small box(set to dynamic actor, rot damp to max and gen movement damp to 0) and a plane whose movement I controll.
small box logic brick set up: Always->Python->Movement
The python script:
import GameLogic as G
cont = G.getCurrentController()
track = cont.getActuator("Movement")
ytrack = track.getLinearVelocity()[1]
print ytrack
I move my plane along the y axis to push the small box. The small box then goes to move up and bounce of the side of the big box.
In console the return for LinearVelocity never exceeded zero.
1)Is there a method to Track/Modify just the general speed of an object regardless of it’s direction?
2)Why does LinearVelocity return 0.0, when the small box obviously changed speed and even direction (when it bounced of the side of the big box).
In the movement actuator “linV” has 5 attributes (x,y,z,L,add), but when I try to “setLinearVelocity” and set a value of 0 for add, I get an error saying that there should be only 4 attributes. Whats the deal?
1)I don’t think there is a method, I am lazy and just do (xvel + yvel + zvel) / 3 or something, but you can definitely do that by using lots of math, probably squareroots and stuff.
In your script “ytrack” is the y velocity exerted by the actuator. To get the y velocity of the object, you need to do a getOwner, and then do owner.getLinearVelocity.
3)If I remember correctly, the force of the actuator that you control in python is (x,y,z,local). I dont think you can enable or disable add, you do it before you start the game, and control the force setting with python.
Ahh, thanks alot anoncompboy. The “owner.getLinearVelocity” returns the values I was looking for. Now if there was only “owner.setLinearVelocity”.
You see the problem is that my moving object needs to be a dynamic actor, it’s not just a matter of location. I need a way to keep the linear velocity no greater than 2 and no less than -2.
I have tried to apply a counter-velocity by doing this:
countermove = cont.getActuator("CMovement")
y = owner.getLinearVelocity()[1]
if y > 2:
y = y - 2
if y < -2:
y = y + 2
countermove.setLinearVelocity(0,-y,0,0)
G.addActiveActuator(countermove,1)
It doesnt work though, because when I push the dynamic object with a plane it shoots out way too fast.
y = owner.getLinearVelocity()[1]
v = 8 ##I decided to use 8 instead of 2
if y > v:
y = -v
if y < -v:
y = v
movement.setLinearVelocity(0,y,0,0)
G.addActiveActuator(movement, 1)
When I hit the ball with my plane the ball shoots out along the y axis at the velocity of about 29 or so.
I am really surprised that there is no velocity restriction option for a dynamic object, it just seems like something common. Don’t you think?
I actually tried to do this in Hellcastle and I couldnt succeed either. Here’s a mock-up of my method:
maxvel = 20
if playervel > maxvel:
(playervel-maxvel) = diff
diff/2 = force
actuator.setForce(0,-force,0,True)
It wanted it to take the exceeded velocity, divide by 2, and apply the negative force. But it did so kind of jumpy, so I trashed the idea. I’d really like to figure this thing out though.
nah, damping just reduces the time a dynamic object will continue to try to follow its trajectory when it is not being affected by any forces (ie air/water drag effect)
The blend is not necessary, because I described the whole scene in detail, in my initial post. In short: just make a “Plane” that you can move forward along the y axis, add a dynamic object with 0 dampening, max rot dampening, write a script for the dynamic object which will restrict its velocity to a constant speed regardless of how hard you hit it with the plane (all of this is using sumo physics with gravity set to 0). If there is anything you still don’t understand, please tell me and I will be glad to explain further, but really I don’t think its all that difficult to set up.
@anoncompboy
Your method is interesting, but as you said it is jumpy (actually my script behaves in a similar manner), so that is not a solution. Although it could lead to one, I hope. Thanks for your effort.
Has anyone noticed that there’s no motion actuator in the Gamelogic reference?
I had more posted here, but I just realized I forgot to do something.
O.K. there seems to be a physics overide as everyone has already said. You can kind of see that because you either have physics or you don’t. You could try turning off the physics after a slight collision delay, maybe, or set a high damp and then linear velocity would take over faster. Which is what I would do but I don’t know what your application is. Think of the problem in reverse, instead of trying to slow it down when it’s going to fast, speed it up when it’s going too slow. There won’t be physics override that way.
The motion actuator is in the Gamelogic doc, its just named something weird like ‘object actuator’ (which is incorrect.)
Social, I dont know if this would apply to your game, but I had this idea. I tried it, but I didnt know python well enough for it to work. I tried to completely rewrite the controls for my character (W,s,a,d). My problem was that with the traditional logic brick setup, going in a diagonal direction would result in running faster, which is unrealistic. So by rewriting the controls in python, I could do something like “if W and A then setlinv of the actuator” and then tell it to go certain values for x and y that would not result in running faster. So anyway, just thought I would stick that out there. Could this method work in your game? Could anyone help me do this?
I’m trying for a Breakout clone (should have probably mentioned that before). I thought that I could do that in less than an hour and then make a little begginer friendly tutorial. Needless to say there were complications. I solved one of them:http://blenderartists.org/forum/showthread.php?t=59907.
The 2nd problem (aka: the one we are discussing here) is that when the playerblock(paddle) sideswipes the ball(dynamic object), the balls velocity increases dramatically due to the extra force exerted on the ball by the paddle. Hence the need to resrict the speed of the dynamic object.
I implemented your “counterforce in reverse” suggestion like this:
y = owner.getLinearVelocity()[1]
x = owner.getLinearVelocity()[0]
v = 7 #What the speed should be restricted to
if y < v and y > 0: #I use "and >/< 0" to ensure that
y = v #statements don't conflict.
if y > -v and y < 0:
y = -v
if x < v and x > 0:
x = v
if x > -v and x < 0:
x = -v
if y == 0 and x == 0:#To get the ball going initially
y = -1
x = 1
movement.setLinearVelocity(x,y,0,0)
G.addActiveActuator(movement, 1)
As with all my previous efforts, this one too returned unconsistent, finnicky and overall abnormal behavior. If you see any mistakes in my script please point them out.
Also, contrary to what you said, I doubt that this method is unaffected by the physics override. When dampening is on max, and my script is going against that dampening (increasing linv when it goes under a certain value), that is the same as going against just the regular dynamic force as I did before (except the counter force was in a different direction). It’s still going against the impulses of the sumo engine. Right?
Thanks for sticking it out there, but as you have probably figured out by now, that would not work in my game. That is because the ball(my dynamic object) is not being controlled by a set of keys. It is “supposed” to adhere to the speed restriction independent of user input. Although if you ever get that working be sure to share the script with me.
If solving this problem helps me realize how to apply it to any of your problems, I will be glad to help you out as well.
Although at this moment things don’t look all that promising.
Uh, correct me if I’m wrong, but do you really need the paddle to “swipe” at the ball? I mean, in all Breakout games, the paddle just moves side to side. There’s no pinball-flipper action involved.
If you take out the “swipe” part, then the ball just needs to start at a certain speed and have maximum restitution and zero damping.