Jump to content

Positioning/Camera Problems


gamecreator
 Share

Recommended Posts

I'm experimenting with a ball game and I have a few problems I'm really hoping there are solutions to.

 

post-368-12673919374501_thumb.jpg

 

First, whenever the ball falls off the edge, I put it back to its starting point but it doesn't quite work. It's always a bit above or below or to the side of where it should land. Is my position code wrong?

 

Second, the camera follow code doesn't work. While it generally does follow the ball, it wobbles up and down and side to side as the ball moves. The slower the ball moves, the slower the camera wobbles.

EDIT: Is it possible that the camera is positioned not on the pivot point of the ball (which is at the center) but rather the bottom of it (which is at 0,0)? I should test this. That would certainly explain the wobble. EDIT2: Tested. No change.

 

Finally, I can't swear on it now because I can't reproduce it, but I think the physics may have changed depending on the program run. I don't yet alter any friction or anything but sometimes the ball made it up some ramps, even if barely, sometimes it only makes it half way. Sometimes it can stay half way up the ramp if I hold the button down, other times it starts rolling back anyway. Anyone ever have this issue and know what causes it?

 

Here's the simple code I'm currently working with (I removed the initialization & loading code for this post):

 

int main()
{
// ...

while(!KeyHit(KEY_ESCAPE))
{

	if(KeyDown(KEY_LEFT)) AddBodyForce(ball,Vec3(-2,0,0));
	if(KeyDown(KEY_RIGHT)) AddBodyForce(ball,Vec3(2,0,0));
	if(KeyDown(KEY_UP)) AddBodyForce(ball,Vec3(0,0,2));
	if(KeyDown(KEY_DOWN)) AddBodyForce(ball,Vec3(0,0,-2));

	//  If the ball fell far enough, restart it from checkpoint
	pos=EntityPosition(ball,1);
	if(pos.Y<-5)
	{
		PositionEntity(ball,Vec3(0.0,1.0,0.0));
		SetBodyVelocity(ball,Vec3(0.0,0.0,0.0),1);
		SetBodyOmega(ball,Vec3(0.0,0.0,0.0),1);
	}

	//  Follow ball with camera
	PositionEntity(camera,Vec3(pos.X,pos.Y+6,pos.Z-5));

	UpdateFramework();
	RenderFramework();

	DrawText(400,400,"X = %f, Y = %f, Z = %f",pos.X,pos.Y,pos.Z);

	Flip(0);
}

exitapp:
return Terminate();
}

 

Any help would be much appreciated!

Link to comment
Share on other sites

how are you creating the ball?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

is the origin of the model centred?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

If you mean the pivot point then yes, in both Max and the Model Viewer, it's centered in the middle of the ball.

 

I just tested replacing the sphere's .phy file with a box .phy file and the camera bouncing goes away, until the ball falls off the edge. Then it wobbles again.

 

Also, unfortunately, after I replaced the ball's .phy file with the correct one, I was able to go up a ramp I was never able to go up before. :)

Link to comment
Share on other sites

Ok. I just solved two of my three problems. For some reason, Leadwerks uses the global position from Max as the pivot point, not the pivot point itself (even though the exporter exports it correctly, as seen in the Model Viewer). This explains the camera wobble. This also explains the misplacing of the ball at 0,0. When the ball was told to go to 0,0, it placed the ball based on where its bottom was. If the bottom was tilted out because the ball moved/rotated a little, it offset the ball and so it was offset that much from 0,0. Follow?

 

Now I hope maybe my physics quirk is fixed too.

 

Thanks everyone for the help!!

 

 

I guess a related follow-up question: is the timing on the physics correct in the code? I mean, will the ball move at the same speed for everyone?

Link to comment
Share on other sites

I want to continue this thread about camera.

I'm programing on Lite-c about 6 years, so usually i place 3rd person camera with converting sphere coordinates to XYZ coordinates, something like

		// moving camera around center
		camera.x = center.x - camera_distance * cos(entity.pan) * cos(camera.tilt);
		camera.y = center.y - camera_distance * sin(entity.pan) * cos(camera.tilt);
		camera.z = center.z - camera_distance * sin(camera.tilt);

 

Now i'm interested in "parent" variant.

// 1) So, now i place camera
camera = GetLayerCamera(layer);

// 2) Then i move it on the offset to pivot
PositionEntity(cam,Vec3(0,4,-2));

// 3) And last one i set pivot to camera's parent, so it would follow pivot with offset.
if (!pivot) {FreeEntity(pivot); }
pivot = CreatePivot(target);
EntityParent(camera, pivot);

 

Now the question: how can i control offset? For example, i want change distance to pivot as player rolls mouse wheel... Do i may to re-position camera as on 2nd step and then assign it to the pivot like in 3rd step?

Working on LeaFAQ :)

Link to comment
Share on other sites

PositionEntity( camera, EntityPosition(camerapivot) );
RotateEntity( camera, EntityRotation(camerapivot) );
MoveEntity( camera, Vec3(0,0,cameraZoffset) );

To move 3rd person camera closer and further, just change the value of cameraZoffset.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

There were some issues when parenting fw.Main.camera to a pivot.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

And... what about collision detection for camera?

What is faster:

- to send 4 rays from every corner of the camera to player, if something intersect ray, then move camera closer

- create pseudo-physic body(capsule, maybe) without mass, and place it between camera and player?

Working on LeaFAQ :)

Link to comment
Share on other sites

Physics body can get stuck in the environment (unless you have some pathfinding for it), so I guess 4 entitypicks is better.

 

I would however move the camera closer only when all picks can't see the player, and not when only 1 can not see.

 

The EntityVisible command also checks for the center pivot of the model only, which is kinda useless.

It would be more useful if there was a parameter to say: 0=center visible, 1=completely visible, 2=partially visible. Then you could use option 2 for 3rd person camera checks.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

//Physics body can get stuck

No-no... without physic, just for collision detection.

 

//I would however move the camera closer only when all picks can't see the player, and not when only 1 can not see.

Why? Then, its better to send only 1 pick, from the camera point.

Working on LeaFAQ :)

Link to comment
Share on other sites

Why? Then, its better to send only 1 pick, from the camera point.
It's quite annoying when the camera moves just because a little toe is hiding behind a little stone on the ground (one ray can not see 1 corner).

 

I'm much happier when the camera doesn't move closer when I still can see 1cm of the top of my head, because then I know the rest of the body is also there, no need to show it.

 

Only when I can't see anything of the player body, then I lose orientation and need to move the camera closer until I can see at least something of the player.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

1 ray cast works just fine. You can determine what entity types would effect the raycast so you could make some things not be affected by this raycast.

 

The EntityVisible command also checks for the center pivot of the model only, which is kinda useless.

 

This is why you don't parent the camera to the player, but instead create a pivot that follows the player. You offset the pivot from the player to determine where you want the camera pointing (the head most likely). Then you do entity visible between the player pivot and the camera or camera pivot.

 

The other reason to do this is that most 3rd person games allow you to rotate the camera freely from the player rotating. By having a player pivot that follows the player, you can just rotate that and the camera will follow since it's parented to that player pivot. This will rotate the camera independently from the player very easily.

 

Note that when you do the entity visible between the 2 pivots you'll have to worry about the actual player model. I generally just hide the player model, do the entity visible check, then unhide the player model.

Link to comment
Share on other sites

//The other reason to do this is that most 3rd person games allow you to rotate the camera freely from the player rotating. By having a player pivot that follows the player, you can just rotate that and the camera will follow since it's parented to that player pivot. This will rotate the camera independently from the player very easily.

 

Of course, i just wanted to handle camera to something like player :)

Working on LeaFAQ :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...