0
\$\begingroup\$

I'm trying to move code from unity 3d to stride 3d but I have huge issues as IDE doesn't help me find words when I type as unity 3d does

the unity 3d code that works:

public Transform Planet; // to rotate to
void Update(){
    PlanetDirection = Planet.position - transform.position;
    planetDistance = MathFunctions.V3Distance(transform.position, Planet.position);
    Ray ray = new Ray(transform.position, PlanetDirection);
    RaycastHit hit;
    if (Planet.GetComponent<Collider>().Raycast(ray, out hit, planetDistance)  ){
        transform.rotation = Quaternion.LookRotation( Vector3.Cross(transform.right, hit.normal) , hit.normal);
    }
}

this is updated stride code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Stride.Core.Mathematics;
using Stride.Input;
using Stride.Engine;
using Stride.Physics;

namespace example1{
    public class PlanetaryMovement : SyncScript{
        public Colliders PlanetCollider;
        public Entity Planet; // to rotate to
        //maybe I don't need so much only Simulation
        Stride.Physics.Simulation sim;
        Vector3 near = this.Entity.TransformComponent.position;
        Vector3 to = Planet.TransformComponent.position;
        //var result = sim.Raycast(vectorNear.XYZ(), vectorFar.XYZ());
        IList<HitResult> hit = new IList<HitResult>();
        CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter;
        
        public override void Start(){
        }

        public override void Update(){
            sim.RaycastPenetrating(near, to, hit, filterGroup);
        
            PhysicsComponent col;
            for(int i=0; i< hit.Count; i++){
                if (PlanetCollider == hit[i].Collider){
                    this.Entity.Quaternion.Rotate(hit[i].Normal);
                }
            }
        }
    }
}

and the reference with witch I was trying to figure out how to translate my code

EDIT: -Updated the code errors that still exists:

[C:\programming\Stride 3D\example1\example1\Movement.cs(14,12)]: Error: The type or namespace name 'Colliders' could not be found (are you missing a using directive or an assembly reference?)

what I need is to link the HitResult with Planet somehow I don't know what to use to compare them.

Raycasting Simulation Simulation HitResult Physics quaternion

\$\endgroup\$
2
  • \$\begingroup\$ Converting code from an engine to another is not really game development and is more about "code". Code questions should be asked on stack overflow. \$\endgroup\$
    – Vaillancourt
    Aug 24, 2021 at 11:12
  • \$\begingroup\$ If you ever manage to get your code working, but you have an issue with it, then please update the question with your new issue and we'll help you reopen it. \$\endgroup\$
    – Vaillancourt
    Aug 24, 2021 at 11:21

1 Answer 1

0
\$\begingroup\$

I think you just forgot to using Stride.Physics; and where vector3 near first letter must be upper like this Vector3 near. In the end you should using Visual Studio because it helps fix errors like these.

\$\endgroup\$
2
  • \$\begingroup\$ actually I'm using Visual Studio but it doen't help me find words. and the strides IDE doesn't work like in the tutorial works and I don't know how to fix that, ... \$\endgroup\$
    – MilitaryG
    Aug 6, 2021 at 14:56
  • \$\begingroup\$ updated the code and it still doesn't know what Colliders are [C:\programming\Stride 3D\example1\example1\Movement.cs(14,12)]: Error: The type or namespace name 'Colliders' could not be found (are you missing a using directive or an assembly reference?) \$\endgroup\$
    – MilitaryG
    Aug 12, 2021 at 9:49

Not the answer you're looking for? Browse other questions tagged .