I’m sort of trying to make a generic marble game but I’m having problems with the controls and camera. Currently my marble moves by adding force to the global axes regardless of rotation of the camera so it’s really odd. For example if the camera is looking at -Y direction and I press the up arrow key to go forward the marble goes towards the camera to the +Y direction. I need it go -Y direction where the camera is pointing. Here’s a video I found that has the type of movement I need.
Also it appears that my camera is not 100% fixed to the center of the marble but rather waves around slightly when moving. Again see the video.
Woah woah now you’re throwing math terms at me like a pro. I have zero experience with Python and I most certainly do not have the time to invest or interested to learn it. I’m just working with the Logic Editor here.
There is not much to see. For the models themselves it’s just a cube or two and the ball. As for the logic, it’s just the basic keyboard sensors and motion actuators.
What I need is the ball to use the camera’s local coordinates. So where the camera is pointing that is the Y axis for the ball and camera’s left/right is the ball’s x axis.
Beautiful… Beautiful… This is exactly what I need. (The first script.) I only needed the camera rotation so I simply removed to the zooming and pitch logic+script, redid parenting and remapped to camera rotation from arrow keys to A and D. (Ball controls) Now it works exactly the way I want. I can’t thank you enough!
Edit: Well this is odd. There is something special about your plane mesh as the ball only works on that. If I add a regular plane the ball doesn’t move on it. What’s the problem?
There is something special about your plane mesh as the ball only works on that. If I add a regular plane the ball doesn’t move on it. What’s the problem?
Yes you need to assign a material on the ground with a friction value (Material –> Physics –> Friction).
The reason is that the first script is using torque. That means that the ball gets an rotation force. When you have no friction the ball only rotates on the place.
I see, but that still does not work. I’ve appended (To new save) the sphere, camera and the camRot empty + scripts but my ball still does not move. I’ve double checked everything so they are similar to your save. The logic and scripts are there. If I append your plane, it moves on that but if I add a regular plane it doesn’t move at all. I also went thru all the properties and made sure my plane is identical to your plane, but no. It just stays perfectly still and keyboard does nothing. It doesn’t even spin on it’s place. I can only rotate the camera.
On the red plan the property “Ground” is missing. If the ball don’t hit the property “Ground” the ball cant rotate.
If you don’t like to make a property on the ground planes, you can delete the property on the collision sensor, but than the ball can rotate and jump on every object also on walls.
You can also use a ray sensor (without property) on the camera empty and connect that to the sphere Python controller.
If you like that the ball can rotate in the air move the line 54 one tab out.
I thought it was something like that too. But. I checked every tab and every option on that plane and I could not see anything with the word “Ground”. I assume it would be in the “Custom Properties” option, but I can’t find it.
Let’s just keep it all in one thread. How would I allow movement while in air? I would need to be able to steer my ball while it is in air by adding force to it, not torque. Currently the ball moves on ground with torque. I tried doing what you said and editing line 54, but that adds torque to the ball, not force.
Yes you must use force if you want to move in air.
You can change to use only force.
Line 53 to 54
# set force to the game object
o.applyForce([jOri.x, jOri.y, 0.0], False)
Or you can use force only if the ball is in the air.
Line 53 to 57
# set torque to the game object
o.applyTorque([jOri.x, jOri.y, 0.0], False)
else:
# set force to the game object
o.applyForce([jOri.x, jOri.y, 0.0], False)
Looks promising though is getting more and more complex. Here’s a part of code that I’ve edited.
# create a verctor with the
TorVec = m.Vector((-y,x,0.0))
# get first child object (pivot) from game object (cube)
pivot = o.children[0]
# get child object (pivot) orientation matrix
pivOri = pivot.worldOrientation
# rotate vector acording to the pivot
TorVec.rotate(pivOri)
#Don't move and rotate if the ball not hit the ground
if ground.positive:
#Jumping button positive
if jump.positive:
zSpeed = 400.0 #Jumping force
o.applyForce([0.0,0.0,zSpeed], False)
# set torque to the game object
o.applyTorque([TorVec.x, TorVec.y, 0.0], False)
else:
# set force to the game object
o.applyForce([ForVec.x, ForVec.y, 0.0], False)
It works great on forward/backward air motion but it is mirrored on the left/right motion. This also presented a new problem with the camera. I need to prevent the camera rotation when the ball is in air. (I’ve set the camera to rotate when you press the A and D keys.) How would I do that?
Edit: On a second though, let’s scrap that camera thing. I think just fixing the left/right movement should do it.
Edit2: I just noticed that the air movement axes are not rotated with the ball.