Attaching camera to a car and making it look realistic

Hi Geoff,

I have asked this before, but still am confused by it. On Scene 2 of https://edu.cospaces.io/WHG-GJE, the car continues to drive through the walls. Physics is turned on with the car and the walls, and the car is attached to the camera. We feel as if we have tried everything and it still doesn’t ‘bounce’ off the wall. How could we fix this? Once again, thanks for your help!

Hi Kelly,

It’s a little hard to tell exactly what’s happening without remixing it and seeing inside, but here’s a few pointers:

  • When overriding keys with onkeypress events, all notions of grid boundaries disappear (unless you enforce them).
  • Anything outside the grid will not have physics applied.
  • If an object travels fast enough it may pass through any object with physics (due to movement occurring between frames)

Hope that helps! Let me know if you have any further questions.

Geoff @ TechLeap

Thanks Geoff! However, I’m not sure what you mean by this:

  • When overriding keys with onkeypress events, all notions of grid boundaries disappear (unless you enforce them).

Also, I assumed you could remix it and look inside.

I can’t remix the space unless you make it remixable :blush: Normally, when navigating a CoSpace, you cannot walk/fly outside of the grid (shown in the Editor) because there are grid boundaries which prevent this. The environment outside of the grid doesn’t have physics applied to it. I assume you are using when key is pressed events to control the car. When you use these events to control the car, the grid boundaries don’t apply, so your car can go outside of the grid.

Does that make sense?

Geoff @ TechLeap

Thanks Geoff,

We also have this issue. A student wants to have the boy ‘run’ and the camera to follow when he presses the W key. However, after 1 second the boy stops moving because we can’t get the camera to continue to follow him. This is in Scene 1 of https://edu.cospaces.io/WHG-GJE. You should be able to remix it. Any thoughts?

Hi Kelly,

Every time you make a change on a CoSpace, if you want to share that change, you need to click Share > Update to publish the changes. There are no CoBlocks in the CoSpace you shared, so I’m guessing this is what has happened.

However, I’m guessing you just want the camera to follow the boy? Simply attach the camera to the boy by dragging the Camera object onto the Boy in the Scene Inspector (list of objects in top-left tab) - this sets it as a child of the Boy.

Hope that helps! Let me know if you have any further questions.

Geoff @ TechLeap

This is the link: https://edu.cospaces.io/WHG-GJE

This is the script. But the camera WILL NOT move forward, even though it is attached to the boy.

https://edu.cospaces.io/WHG-GJE

This is the other game. In Scene 2, the car keeps driving through the wall. I believe you can now watch the game. https://edu.cospaces.io/WHG-GJE

Hi @Kelly_Nickell,

I’ve fixed Scene 1. This should tell your students all they need to know about the game mechanics they want to achieve (hopefully). Get them to Remix and compare. Notice the Physics I’ve added.

Hope that helps! Let me know if you have any further queries.

Geoff @ TechLeap

Thanks Geoff! But when I play it, when I turn to the left to go around the corner, the character doesn’t turn. The camera does.

Never mind! I didn’t know I had to press A and D for that to work.

It’s possible to disable the mouse interaction so that only keys can be used, by creating a script with the following code:

Input.onKeyPressed(function(){},‘left_mouse_button’);

Thanks Geoff,

In this game, in Scene 2, if you press B to get out of the directions, and press W to move the car, the car will still go through some walls.

https://edu.cospaces.io/WHG-GJE

I am sorry for all the questions, but you are the only person who can help us! Thanks!

Hi @Kelly_Nickell,

There are a couple of things to do and understand:

  1. To simplify things, I suggest putting a giant transparent cuboid around the buildings and turning on Physics for it.

  2. You can try adding an additional collision event to the above cuboids, so if the car collides with them, the car moves back slightly.

  3. Frame rate - if an object moves too fast it can move through other physics objects in between frames (depending on the GPU of your computer); therefore slowing down the car may help.

  4. Adding a restrict Car rotation CoBlock will help prevent the car flipping over; however it will not stop the car being pushed out of another object.

@Nikolay, do you have any other suggestions?

Geoff @ TechLeap

I would recommend to implement all of the above items.
You could also play with the mass, friction and forces to achieve best results (there is a simple example in this thread)

1 Like

Thanks Geoff!

Also, are you one of the owners of CoSpaces? I only need about 4 licenses for Monday (2 classes with about 64 total students), but it appears I can only go up to 100 licenses and nowhere in between.

Hi @Kelly_Nickell,

I’m a training partner for CoSpaces Edu. If you contact the sales team they can set you up with the exact number of seats you need :blush:

Let me know if you have any issues getting the licenses you need.

Geoff @ TechLeap

HI again Geoff! I was wondering if you could help these students out. On Scene 2 and Scene 3 of https://edu.cospaces.io/RQU-QDZ they want the arrows to move up the wall. However, each time you play, they want a different arrow to move each time. For example, the red arrow will move first next game, but if you play again, the computer will choose a different arrow to move first. Whichever arrow moves first, you press the corresponding arrow key on the keyboard, which triggers another random arrow to move up the wall. you then click that corresponding key on the keyboard, triggering the 3rd arrow.

Hi Kelly,

Please create a separate topic for this post, and have a think about what the question is :blush:

Many thanks,
Geoff