Hi, how can I make a sphere gameobject move forwards while it looks like it’s rolling (rotating y axis) in C#?
Re-read the other thread and check the example project I sent you;
No that’s different, I just want the ball to increase it’s z position at a specific speed instead of always moving forward like this player.transform.Translate(Vector3.forward * Time.deltaTime * speed);
Pretty much everything you need is in the thread and the project - just figure out how it works and adapt it as you need. The project I sent you literally rolls the sphere around x and rotates around y while it moves… take a look at how it works again.
I tried new vector 3 and increasing the z position by 1 in void update but that made it go super fast
Editing your question after I reply doesn’t help my answers look right!
The general ideas about how you can move and rotate objects based on input are in there, with a basic nested structure of gameobjects to make everything pretty clear. You can unparent the camera if needed. You should be able to learn what’s going on and change it to solve what you’re asking. Otherwise, you’re just asking for other people to write your scripts for you without learning much.
not sure if this is similar to what you are looking for?
I already have unparented the camera and I’ve written a script that functions but not nicely. So it works except the player movement is glitchy. I added an animation to the X axis of the ball so it looks like it’s actually rolling, then I wrote a script for the camera to make it follow the player how I want it to. Now I added this code player.transform.Translate(new Vector3(player.transform.position.x,player.transform.position.y, (player.transform.position.z + 1)) * Time.deltaTime/speed); to the player instead of this player.transform.Translate(Vector3.forward * Time.deltaTime * speed); because I figured that if the ball is rotating it won’t always be moving forwards, right? Now all I want to do it make the balls z position increase smoothly using a certain speed. The code I have now works but not very efficiently. I don’t even know what I’m looking at in this other project.
Yes thanks! That is exactly what I needed! I am just having one issue, my ball is moving in the opposite direction to what it should be. The rotation is fine, just the movement isn’t. I tried changing a few variables but not really sure which one I should change?
The code I wrote comments every single step to explain what it does. I’m not sure how to help further without writing the exact script you need for you.
The rig accepts input and moves a ball in x/z while rolling. No, the two are not fully connected as we were discussing one example of how something might be rigged up. ie. the ball doesn’t roll the correct amount that it has moved in x/y (this was left as something you could add afterwards once you understood the mechanic). In this case you need to convert the distance moved in x/z to an angle to rotate the ball by. @mgear 's post sounds like it has a line of code you can use - just make sure you understand it and you should be able to apply it easily enough.
I think I’ve got it thanks