How to 3rd person ball controller that can look up and down?

Noob Warning

I have wanted to make a 3rd person ball game where the ball rolls towards the camera direction and the ability to look vertically as will.

currently, I have looked at every tutorial on how to make a ball controller but they all lack in some key aspects of what I want to make. either they cant look vertically, it’s outdated and doesn’t work with the current Upbge version, or for most of them the camera is not part of the tutorial.

problems I keep running into are when I try to parent both vertically and horizontal camera hooks to the ball’s vertex only one works and the other just doesn’t. I have tried to make the ball control the horizontal camera but that comes with the problem of the camera rotating with the ball or the ball not going forwards in the direction of the camera.

I have reached out to the tutorial creators for help but got no reply or have been told that it’s passable through python but they don’t know how either or that I should just switch to a different game engine. So now im reaching out to this forum in hopes someone has the answers I have been seeking for months now.

This is really my last hope and might quit on my project at this point.

can u show us an animation or link how it is supposed to work? thx

Right sorry, I want to have controls like in this project on youtube

but this project has been abandoned and is outdated. I have tried to download the project and dissect it in hopes of figuring out how to implement it in the current version of upbge but no luck. maybe some of you guys with much more experience could make sense of it.

what I want is almost the same controls as the video but without the weapons and just the ball alone.

here is where I got the Blend. file in case someone wants to dissect it. https://blendswap.com/blend/19248

import bge
from bge import logic as GL
 scene = GL.getCurrentScene()

def init(cont):
from bge import events
keyboard = bge.keyboard.inputs()

own = cont.owner
ball = scene.objects['ball']

keyW = keyboard[events.WKEY].active

own.worldPosition = ball.worldPosition #assign position

if keyW:
ball.applyRotation((1.0, 0.0, 0.0), True) # rotation sphere
ball.applyMovement((0.0, -1.0, 0.0), True) # movement sphere

#For mouse look create empty and assign for empty sensor - mouse movement and actuators mouselook and add this simply script for empty not for ball/sphere

1 Like

ok, I have tried this and neither the ball nor the camera moves.

i parent the camera to the empty and then the empty to the balls vertex. I’m not sure if it’s the fault of my parenting. I honestly don’t know what I did wrong.

Don’t put the script between the mouse sensor and the actuator, connetct these directly.
Use an always sensor for the script.

Wow, the example game was a lot of effort! I looked if it was useful to excerpt his setup for UPBGE but found out it is even more complicated than my own solution.

You surely want to your controls relative to the camera view and not bound to world coordinates.

So I made a new empty file and appended only the ball and camera system and stripped off everything else from the scene and the scripts.
(This setup uses 2 empties for the camera. It would also work with only 1 empty but this way you have more control of smooth camera Motion / Rotation)
The camera system is in collection that is set to non-selectable, change this in case you want to edit it.

Ball:   
    W A S D move
    SPACE jump
View:
    Mouse or Arrow-Keys: Rotate view
    Mousewheel or Page-up/Page-down: Zoom
    Middle Mousebutton or Home: Reset Zoom
    F: Camera Follows Ball On/Off

Ball has 2 game properties
'Mouse_sensitivity':
    Camera speed
'Keyboard_sensitivity':
    Ball Speed

Objects with property "obstacle" will let the camera go beyond. (also the floor has this)
Objects with property "transparent" and suitable Material will go transparent when view is blocked.

UPBGE_0.3_Ball.blend (1.1 MB)

1 Like

Holy… this is really complicated for me… it has the idea down but I have no idea on how to manipulate or work with these controls.

That being said I really love these controls and will keep messing around with them to advance my understanding of python. I also am thinking about implementing these controls in a different project I was thinking about.

Also thanks to your comment on what I did wrong on the Villa89 code I tried it and is exactly what I wanted but it still doesn’t move forwards toward where I am aiming unlike yours musikai. The camera movement is set now but is there any way to have the WASD force apply relatively to where the camera is facing and not where the ball is facing?

I got another blend. File that has the movement I want but doesn’t have the ability to look vertically and if I try to add Villa89 code it either breaks it or doesn’t work. https://youtu.be/qfMi3LKzZmc

Never mind after messing around with your blend file I have found out how to play around with it and have noticed it’s perfect for what I want. Thank you so much!! now I can start getting into other aspects of my project that I have been only dreaming about before now. thank you so much again.

Yes, I hope you can have good use of it :slight_smile:
I again cleaned up the code of the above file a bit and now the mouse_sensitivity property of the Ball applies to the mouse-view-speed. (before it just was a relict for the ball movement)

What isn’t in this file: That the camera moves around obstacles (or the ground). It now just stops when close to the ground (and even that isn’t reliable)

ok, I see that now but ill do a camera collision later. other than that I am loving these and has opened up my project tenfold. I can’t thank you enough. I have been trying to make these controls for months and was on the brink of giving up.

one quick question how do you remove the invert if the camera passes y5? sorry if this is a dumb question I am trying to wrap my head around this but it really is complicated for me with 0 python experience.

y5 ?
Do you mean when the camera looks from down below? Yes, then there is some “strange” inverting.
I admit that I don’t understand the maths there when I found this solution somewhere. (it worked for my purpose)
(Perhaps I was in a similar situation like you, first attempts with python then.)
If I find another solution I let you know.

1 Like

I changed the above file:

  • the movement is now consistent to camera view in all angles. (I replaced the math I couldn’t understand with easy Vector math.)
  • For mouse movement input I now used the more exact brick (which doesn’t need the rounding bug workaround of the ‘python only’-solution).
  • The Zoom function is now relative to the distance.
  • The angle limit works a bit better.
1 Like

ok now, this is a python that I’m a little more accustomed to (Vector I missed you XD) and it fixes the problem that I was having (so it’s a win-win). now I’m gonna be messing around with the camera collision which for me is a lot easier. you have been a lifesaver and I can’t thank you enough. if I can help you with anything I will hands down.

1 Like

Thank you!! It is really fun.

Now the above file is updated.
The limits are working reliable now. And here are some specials:

  • Objects with property “obstacle” will let the camera go beyond. (also the floor has this)

  • Objects with property “transparent” and suitable Material will go transparent when view is blocked. A dummy mesh with collision sensor is used instead of a raycast so that all objects in line_of_view are detected.

1 Like

OMG you’re a god. you have single handly helped me with all the controls of my project. I really don’t know what to say. you have gifted me more than anything I have gotten in this Christmas (which honesty all I got was 2 shorts that didn’t fit me but). i really appreciate this and will never forget what you have done for me.

1 Like

Thank you :slight_smile:

One last update happened. The view angle limiter had some quirks.
Now it seems to work reliable. (with a workaound for the Euler suddenly changing directions)

1 Like

I had to try that out:
Camera following ball direction. You can turn that on/off with Space key in the updated blend.
Nice thing is that manual mouse view still works even in that mode.

1 Like

if you want you can join my discord server so we can keep in touch on each other’s developments and have a place to go if we need help or anything from the other. I would like to share some of the things I have done but this website still sees me as a newcomer so it doesn’t let me share videos or projects yet. it’s just a quick-made server with no one in it yet. https://discord.gg/hTVwRcUd or you could add me LordAirend#5711

Thanks! I’m always interested in other people’s stuff. On Discord I’m not active (only guest member to look into upbge/range etc. servers)
I somewhat prefer the classic way of forums and find blenderartists a wonderful site to share videos, blend files and knowledge!

(little bugfix update for the range of obstacle raycast and
F: toggle follow mode
SPACE: jump)