- Home /
Smooth movement over seem?
I have a script to generate a world for testing purposes, where I place, (or randomly place), simple cube primitives in a platformer-like way, (creating a 2D game with 3D).
The level I use for testing is a Mario Bros. lvl 1 copy, (it has great elements for testing ). I have a code that uses XY coords, a direction and number of cubes to instantiate in that direction. This works execellently.
My problem is that when my "Player" object moves, and hits a "seem", it does a little "jolt", which looks stupid, but also messes with my movement script. I have trie using other colliders, and I have tried to "soften" the collision detection, but to no avail.
Thanks for the help! Frank
If someone is interested, here's an approximation of my level creation script, (my actual is much more versatile but is copyrighted, by my employer, so I can't share it): using UnityEngine; using System.Collections;
public class Level : MonoBehaviour {
//new game objects
GameObject enviroment;
GameObject enviromentGroup;
void Start()
{
// function to create the predetermened level layout
// TODO: Allow for variables to trigger the selected level to create
LoadLevel();
}
// Method to hold the instruction for creating a level
public void LoadLevel()
{
//Create a parent object for the level
enviromentGroup = new GameObject("Grouped Enviroment Objects");
// Populate world with cubes
CreateEnviromentElementCube(-15f, -1f, 25, true);
/* ##### LEVEL BOUNDERIES ##### */
// values: X, Y, Amount, Is X-direction?
CreateEnviromentElementCube(-50f, -50f, 100, true); // Left Bottom to Right Bottom
CreateEnviromentElementCube(-50f, -49f, 100, false); // Left Bottom to Left Top
CreateEnviromentElementCube(-49f, 50f, 100, true); // Left Top to Right Top
CreateEnviromentElementCube(50f, -50f, 100, false); // Right Top to Right Bottom
}
// method to instatiate "levelCubes"
public void CreateEnviromentElementCube(float varPosX1, float varPosY1, int varNumBlocks, bool varBlockDirection)
{
// cycle through the given number of blocks in given direction
for(int i = 0; i< varNumBlocks; i++)
{
// create cubes in level
enviroment = GameObject.CreatePrimitive(PrimitiveType.Cube);
enviroment.name = "Enviroment";
enviroment.transform.parent = enviromentGroup.transform;
enviroment.transform.position = new Vector3(varPosX1, varPosY1, 0f);
// add values to iterate one block at desired direction | first block is in the exact given position always
if (varBlockDirection) varPosX1 = varPosX1 + 1f;
if (!varBlockDirection) varPosY1 = varPosY1 + 1f;
}
}
}
Hey bud, sounds a little bit like your colliders are just off touching as one level end section to your level start section gets instantiated.
This might be as easy as just stretching your box/sphere/whatever colliders you have on the gameobject that is your level floor etc, just stretch your collider(s)(not the transform) approx 0.05 over the edge of your visible mesh. You might find this will indeed, resolve your jolting problem, which could be happening due to your controller discovering a distance between one colliding object and the next.
you could do that in the code, somewhere during your
//create cubes in level part
environment.transform.boxCollider = new Vector3(1.05f, 1.0f, 0.0f);
giving that extra bit to your x axis in the assignment.
There are some improvement, but even playing around with it, it just don't do it.
I suspect that the physics engine in itself detects a $$anonymous$$uscule difference during rendering, and so it becomes a "bump". I suspect that I might need to "group" a set of cubes and create a collider around them all, or I might repurpose my script to create one elongated "cube", for each group of them :-/
tnx anyways, I'll just soldier on ;-)
Your answer
![](https://koobas.hobune.stream/wayback/20220613141455im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to incorporate Time.deltaTime into existing script 1 Answer
How to smoothen movement of a child object? 1 Answer
How can i drag objects smoothly with touch? Please help me with this code! 1 Answer
A bit shaky when translating 1 Answer
What is the cause of the distorted movement of my character? 0 Answers