Changing angle in a kinematic collision

IN a platformer, I want to make a character walk up a curve. I want the character to change rotation when moving up that curve. The character is a kinematic collision object.

For example, sonic games have sonic rotate on a loop

Is there any way to do this?

2 Likes

Yes, it’s possible. I remember seeing an example @sicher made but not sure if that source was posted publicly.

1 Like

What’s stopping you from using go.set_rotation, go.animate, etc.?

1 Like

I need to find the angle at which the object collides with the ground first. And then I can do that

Or something else that ensures that detects that the slope at the midpoint of the bottom of the character is parallel to the slope of the ground below. At least that’s what I think I need in order to do this.

To visually expalin…

1 Like

I think what you’re looking for is the contact point normal:

4 Likes

Exactly. Rotating the player sprite to match the orientation of the normal should do the trick; but remember, there are edge cases - in some weird situations / exceptions you might want to handle rotation differently. Best of luck @SN_Trett, manual physics controllers are tricky to work with.

3 Likes

To start, I’ve added this line upon a collision response, but this syntax might be wrong. It should set the rotation of the game object to a new quaternion, made from the normal.

go.set_rotation(vmath.quat_basis(message.normal, vmath.vector3(0,0,0), vmath.vector3(0,0,0)))

I am not really sure how to work with quaternions as a newbie, so is this right?
Otherwise, how would I create a new quaternion with the vector3 of the normal?

Also, should a main camera be a child of a character object, which adjusts once the character rotates,
or a separate entity, that is fixed in rotation, and sets its position to a character’s at every frame?

1 Like

Not quite - I think you’ll want to find the angle of the normal vector, and rotate the sprite around the z axis by that angle:

go.set_rotation(vmath.quat_axis_z(math.atan2(message.normal.y, message.normal.x)))

Try that. You might need to add 3.14159 to the math.atan2 to flip the sprite around, but that should work as a starting point. Keep in mind that angles for game objects are done in radians, not degrees - objects use radians and the gui uses degrees last time I checked, which leads to some confusion.

2 Likes

This depends. It is convenient to have the camera attached to the player collection, since you get all of the camera movement for free, but if you want a camera with a more advanced behaviour, perhaps with a camera window or some kind of snapping it might be better to have it as a separate game object and update it every frame. A colleague shared this excellent article on cameras today: http://www.gamasutra.com/blogs/ItayKeren/20150511/243083/Scroll_Back_The_Theory_and_Practice_of_Cameras_in_SideScrollers.php

1 Like